Skip to content

Commit

Permalink
sc_*_process: remove dynamic processes from process_table
Browse files Browse the repository at this point in the history
Processes spawned during start_of_simulation() are considered
dynamic processes, yet are still stored in the kernel's process
table during initialization.

The check in the destructors needs to catch these processes as
well to avoid corruption of the process table during simulation
teardown.

This patch distinguishes between
  * SPAWN_ELAB  (spawned during elaboration, static processes)
  * SPAWN_START (spawned during simulation start, dynamic process)
  * SPAWN_SIM   (spawned during simulation, dynamic process)

and to categorize dynamic() processes and remove all entries
correctly from the process table.
  • Loading branch information
pah committed Apr 28, 2018
1 parent a6a187d commit b1f5117
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/sysc/kernel/sc_method_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ sc_method_process::sc_method_process( const char* name_p,
//------------------------------------------------------------------------------
sc_method_process::~sc_method_process()
{
if( !dynamic() ) {
// Remove from simcontext, if not spawned during simulation
if( m_dynamic_proc != SPAWN_SIM ) {
simcontext()->remove_process(this);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/sysc/kernel/sc_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ sc_process_b::sc_process_b( const char* name_p, bool is_thread, bool free_host,
m_active_areset_n(0),
m_active_reset_n(0),
m_dont_init( false ),
m_dynamic_proc( simcontext()->elaboration_done() ),
m_dynamic_proc(),
m_event_p(0),
m_event_count(0),
m_event_list_p(0),
Expand Down Expand Up @@ -583,6 +583,11 @@ sc_process_b::sc_process_b( const char* name_p, bool is_thread, bool free_host,
m_trigger_type(STATIC),
m_unwinding(false)
{
// Check spawn phase: m_ready_to_simulate is set *after* elaboration_done()
unsigned spawned = SPAWN_ELAB;
spawned += simcontext()->elaboration_done(); // -> SPAWN_START, if true
spawned += simcontext()->m_ready_to_simulate; // -> SPAWN_SIM, if true
m_dynamic_proc = static_cast<spawn_t>(spawned);

// THIS OBJECT INSTANCE IS NOW THE LAST CREATED PROCESS:

Expand Down
11 changes: 9 additions & 2 deletions src/sysc/kernel/sc_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ class SC_API sc_process_b : public sc_object {
AND_LIST_TIMEOUT
};

protected:
enum spawn_t {
SPAWN_ELAB = 0x0, // spawned during elaboration (static process)
SPAWN_START = 0x1, // spawned during simulation start (dynamic process)
SPAWN_SIM = 0x2 // spawned during simulation (dynamic process)
};

public:
sc_process_b( const char* name_p, bool is_thread, bool free_host,
SC_ENTRY_FUNC method_p, sc_process_host* host_p,
Expand All @@ -356,7 +363,7 @@ class SC_API sc_process_b : public sc_object {
protected:
virtual void add_child_object( sc_object* );
void add_static_event( const sc_event& );
bool dynamic() const { return m_dynamic_proc; }
bool dynamic() const { return m_dynamic_proc != SPAWN_ELAB; }
const char* gen_unique_name( const char* basename_, bool preserve_first );
inline sc_report* get_last_report() { return m_last_report_p; }
inline bool is_disabled() const;
Expand Down Expand Up @@ -418,7 +425,7 @@ class SC_API sc_process_b : public sc_object {
int m_active_areset_n; // number of aresets active.
int m_active_reset_n; // number of resets active.
bool m_dont_init; // true: no initialize call.
bool m_dynamic_proc; // true: after elaboration.
spawn_t m_dynamic_proc; // SPAWN_ELAB, SPAWN_START, SPAWN_SIM
const sc_event* m_event_p; // Dynamic event waiting on.
int m_event_count; // number of events.
const sc_event_list* m_event_list_p; // event list waiting on.
Expand Down
3 changes: 2 additions & 1 deletion src/sysc/kernel/sc_thread_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ sc_thread_process::~sc_thread_process()
m_cor_p = 0;
}

if( !dynamic() ) {
// Remove from simcontext, if not spawned during simulation
if( m_dynamic_proc != SPAWN_SIM ) {
simcontext()->remove_process(this);
}
}
Expand Down

0 comments on commit b1f5117

Please sign in to comment.