Skip to content

Commit b4dada7

Browse files
Add simcontext to sc_object, make simcontext thread local, handle sub-simcontext construction in simcontext::init
Signed-off-by: Mark Burton <mburton@quicinc.com>
1 parent f549985 commit b4dada7

File tree

11 files changed

+47
-35
lines changed

11 files changed

+47
-35
lines changed

src/sysc/communication/sc_prim_channel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace sc_core {
4848
// constructors
4949

5050
sc_prim_channel::sc_prim_channel()
51-
: sc_object( 0 ),
51+
: sc_object(),
5252
m_registry( simcontext()->get_prim_channel_registry() ),
5353
m_update_next_p( 0 )
5454
{

src/sysc/kernel/sc_module.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ sc_module::sc_module_init()
116116
*
117117
*/
118118

119-
sc_module::sc_module()
119+
sc_module::sc_module(sc_simcontext *simc)
120120
: sc_object_host(sc_core::sc_get_curr_simcontext()
121121
->get_object_manager()
122-
->top_of_module_name_stack_name())
122+
->top_of_module_name_stack_name(), simc)
123123
, sensitive(this)
124124
, sensitive_pos(this)
125125
, sensitive_neg(this)
@@ -142,10 +142,10 @@ sc_module::sc_module()
142142
m_module_name_p = mod_name; // must come after sc_module_init call.
143143
}
144144

145-
sc_module::sc_module( const sc_module_name& )
145+
sc_module::sc_module( const sc_module_name&, sc_simcontext *simc)
146146
: sc_object_host(sc_core::sc_get_curr_simcontext()
147147
->get_object_manager()
148-
->top_of_module_name_stack_name())
148+
->top_of_module_name_stack_name(), simc)
149149
, sensitive(this)
150150
, sensitive_pos(this)
151151
, sensitive_neg(this)

src/sysc/kernel/sc_module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class SC_API sc_module
124124
void sc_module_init();
125125

126126
// constructor
127-
sc_module();
128-
sc_module( const sc_module_name& nm ); /* for those used to old style */
127+
sc_module(sc_simcontext *simc=nullptr);
128+
sc_module( const sc_module_name& nm, sc_simcontext *simc=nullptr ); /* for those used to old style */
129129

130130
/* DEPRECATED */ sc_module( const char* nm );
131131
/* DEPRECATED */ sc_module( const std::string& nm );

src/sysc/kernel/sc_object.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@ sc_object::dump(::std::ostream& os) const
157157
// | nm = leaf name for the object.
158158
// +----------------------------------------------------------------------------
159159
void
160-
sc_object::sc_object_init(const char* nm)
160+
sc_object::sc_object_init(const char* nm, sc_simcontext *simc)
161161
{
162162
// SET UP POINTERS TO OBJECT MANAGER, PARENT, AND SIMULATION CONTEXT:
163163
//
164164
// Make the current simcontext the simcontext for this object
165165

166-
m_simc = sc_get_curr_simcontext();
166+
if (!simc) m_simc = sc_get_curr_simcontext();
167+
else m_simc=simc;
168+
167169
m_attr_cltn_p = 0;
168170
sc_object_manager* object_manager = m_simc->get_object_manager();
169171
m_parent = m_simc->active_object();
@@ -183,18 +185,18 @@ sc_object::sc_object_init(const char* nm)
183185
m_simc->add_child_object( this );
184186
}
185187

186-
sc_object::sc_object()
188+
sc_object::sc_object(sc_simcontext *simc)
187189
: m_attr_cltn_p(0), m_name()
188190
, m_parent(0), m_simc(0)
189191
{
190-
sc_object_init( sc_gen_unique_name("object") );
192+
sc_object_init( sc_gen_unique_name("object"), simc );
191193
}
192194

193195
sc_object::sc_object( const sc_object& that )
194196
: m_attr_cltn_p(0), m_name()
195197
, m_parent(0), m_simc(0)
196198
{
197-
sc_object_init( sc_gen_unique_name( that.basename() ) );
199+
sc_object_init( sc_gen_unique_name( that.basename() ), that.m_simc );
198200
}
199201

200202

@@ -204,7 +206,7 @@ object_name_illegal_char(char ch)
204206
return (ch == SC_HIERARCHY_CHAR) || std::isspace(ch);
205207
}
206208

207-
sc_object::sc_object(const char* nm)
209+
sc_object::sc_object(const char* nm, sc_simcontext *simc)
208210
: m_attr_cltn_p(0), m_name()
209211
, m_parent(0), m_simc(0)
210212
{
@@ -244,7 +246,7 @@ sc_object::sc_object(const char* nm)
244246
SC_REPORT_WARNING( SC_ID_ILLEGAL_CHARACTERS_, message.c_str());
245247
}
246248
}
247-
sc_object_init(p);
249+
sc_object_init(p, simc);
248250
sc_mempool::release( namebuf, namebuf_alloc );
249251
}
250252

src/sysc/kernel/sc_object.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#ifndef SC_OBJECT_H
3131
#define SC_OBJECT_H
3232

33+
#include "sc_cor.h"
3334
#include "sysc/kernel/sc_attribute.h"
3435
#include <iostream>
3536

@@ -165,8 +166,8 @@ class SC_API sc_object
165166
virtual ~sc_object();
166167

167168
protected:
168-
sc_object();
169-
sc_object(const char* nm);
169+
sc_object(sc_simcontext *simc=nullptr);
170+
sc_object(const char* nm, sc_simcontext *simc=nullptr);
170171

171172
sc_object( const sc_object& );
172173
sc_object& operator=( const sc_object& );
@@ -176,7 +177,7 @@ class SC_API sc_object
176177

177178
private:
178179
void detach();
179-
void sc_object_init(const char* nm);
180+
void sc_object_init(const char* nm, sc_simcontext *simc=nullptr);
180181

181182
private:
182183

@@ -209,8 +210,8 @@ class SC_API sc_object_host : public sc_object
209210
friend class sc_process_b;
210211
friend SC_API const char* sc_gen_unique_name( const char*, bool preserve_first );
211212
protected:
212-
sc_object_host();
213-
sc_object_host(const char* nm);
213+
sc_object_host(sc_simcontext *simc=nullptr);
214+
sc_object_host(const char* nm, sc_simcontext *simc=nullptr);
214215
virtual ~sc_object_host();
215216

216217
public:

src/sysc/kernel/sc_object_int.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@
3636
namespace sc_core {
3737

3838
inline
39-
sc_object_host::sc_object_host()
40-
: sc_object()
39+
sc_object_host::sc_object_host(sc_simcontext *simc)
40+
: sc_object(simc)
4141
, m_child_events()
4242
, m_child_objects()
4343
, m_name_gen_p()
4444
{}
4545

4646
inline
47-
sc_object_host::sc_object_host(const char* nm)
48-
: sc_object(nm)
47+
sc_object_host::sc_object_host(const char* nm, sc_simcontext *simc)
48+
: sc_object(nm, simc)
4949
, m_child_events()
5050
, m_child_objects()
5151
, m_name_gen_p()

src/sysc/kernel/sc_process.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ namespace sc_core {
4747
// Note the special name for 'non_event' - this makes sure it does not
4848
// appear as a named event.
4949

50-
std::vector<sc_event*> sc_process_handle::empty_event_vector;
51-
std::vector<sc_object*> sc_process_handle::empty_object_vector;
50+
thread_local std::vector<sc_event*> sc_process_handle::empty_event_vector;
51+
thread_local std::vector<sc_object*> sc_process_handle::empty_object_vector;
5252
sc_event& sc_process_handle::non_event() { return sc_get_curr_simcontext()->null_event(); }
5353

5454
// Last process that was created:
5555

56-
sc_process_b* sc_process_b::m_last_created_process_p = 0;
56+
thread_local sc_process_b* sc_process_b::m_last_created_process_p = 0;
5757

5858
//------------------------------------------------------------------------------
5959
//"sc_process_b::add_static_event"

src/sysc/kernel/sc_process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class SC_API sc_process_b : public sc_object_host {
401401
// requesting global suspension.
402402

403403
protected:
404-
static sc_process_b* m_last_created_process_p; // Last process created.
404+
thread_local static sc_process_b* m_last_created_process_p; // Last process created.
405405
};
406406

407407

src/sysc/kernel/sc_process_handle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ class SC_API sc_process_handle {
147147
sc_process_b* m_target_p; // Target for this object instance.
148148

149149
protected:
150-
static std::vector<sc_event*> empty_event_vector; // If m_target_p == 0.
151-
static std::vector<sc_object*> empty_object_vector; // If m_target_p == 0.
150+
thread_local static std::vector<sc_event*> empty_event_vector; // If m_target_p == 0.
151+
thread_local static std::vector<sc_object*> empty_object_vector; // If m_target_p == 0.
152152
static sc_event& non_event(); // If m_target_p == 0.
153153
};
154154

src/sysc/kernel/sc_simcontext.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,14 @@ sc_simcontext::init()
305305

306306
// ALLOCATE VARIOUS MANAGERS AND REGISTRIES:
307307

308-
m_object_manager = new sc_object_manager;
308+
if (sc_curr_simcontext && this!=sc_curr_simcontext) { // Request to re-init due to reset
309+
m_object_manager = sc_curr_simcontext->get_object_manager();
310+
//dynamic_log_verbosity = sc_curr_simcontext->dynamic_log_verbosity; remember to put this back for SC_LOG
311+
m_parent_context=sc_curr_simcontext;
312+
} else {
313+
m_object_manager = new sc_object_manager;
314+
m_parent_context=nullptr;
315+
}
309316
m_module_registry = new sc_module_registry( *this );
310317
m_port_registry = new sc_port_registry( *this );
311318
m_export_registry = new sc_export_registry( *this );
@@ -661,7 +668,7 @@ sc_simcontext::elaborate()
661668
// (not added to public object hierarchy)
662669

663670
m_method_invoker_p =
664-
new sc_invoke_method("$$$$kernel_module$$$$_invoke_method" );
671+
new sc_invoke_method(("$$$$kernel_module$$$$_invoke_method$" + std::to_string((uint64_t)((void*)this))).c_str());
665672

666673
set_simulation_status(SC_BEFORE_END_OF_ELABORATION);
667674
for( int cd = 0; cd != 4; /* empty */ )
@@ -1553,8 +1560,8 @@ void sc_simcontext::post_suspend() const
15531560
static sc_simcontext sc_default_global_context;
15541561
sc_simcontext* sc_curr_simcontext = &sc_default_global_context;
15551562
#else
1556-
SC_API sc_simcontext* sc_curr_simcontext = 0;
1557-
SC_API sc_simcontext* sc_default_global_context = 0;
1563+
thread_local SC_API sc_simcontext* sc_curr_simcontext = 0;
1564+
thread_local SC_API sc_simcontext* sc_default_global_context = 0;
15581565
#endif
15591566
#else
15601567
// Not MT-safe!

0 commit comments

Comments
 (0)