Skip to content

Commit

Permalink
sc_event::none - convert from global variable to function
Browse files Browse the repository at this point in the history
The sc_event::none variable was introduced in
55da81d. The problem with the
introduced implementation is that the created event contains a
reference to the simulation context. This simulation context is created
by the sc_event constructor through the invocation of
sc_get_curr_simcontext() on program startup.

This commit proposes a change which tracks the none event as part of the
simulation context. The change converts sc_event::none to a static
member function which returns a reference to the m_none member of the
current simulation context. This eases reset of the simulation context
as discussed in accellera-official#8.

Neither sc_event::none nor sc_get_curr_simcontext() are currently
mandated by IEEE Std 1666-2011. For this reason, this change should not
affected existing standard-conforming SystemC programs.

Signed-off-by: Sören Tempel <[email protected]>
  • Loading branch information
nmeum committed Sep 24, 2020
1 parent 6041825 commit 1292c02
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sysc/communication/sc_event_finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ sc_event_finder_t<IF>::find_event( sc_interface* if_p ) const
dynamic_cast<const IF*>( port().get_interface() );
if( iface == 0 ) {
report_error( SC_ID_FIND_EVENT_, "port is not bound" );
return sc_event::none;
return sc_event::none();
}
return (const_cast<IF*>( iface )->*m_event_method) ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sysc/communication/sc_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const sc_event&
sc_interface::default_event() const
{
SC_REPORT_WARNING( SC_ID_NO_DEFAULT_EVENT_, 0 );
return sc_event::none;
return sc_event::none();
}


Expand Down
3 changes: 0 additions & 3 deletions src/sysc/kernel/sc_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ using std::strncmp;
// The event class.
// ----------------------------------------------------------------------------

// kernel-internal event, that is never notified
const sc_event sc_event::none( kernel_event, "none" );

const char*
sc_event::basename() const
{
Expand Down
9 changes: 7 additions & 2 deletions src/sysc/kernel/sc_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,13 @@ class SC_API sc_event
// has this event been triggered in the current delta cycle?
bool triggered() const;

// never notified event
static const sc_event none;
// returns never notified event
static const sc_event& none(void) {
sc_simcontext *sc = sc_get_curr_simcontext();
if (!sc->m_none_event)
sc->m_none_event = new sc_event(sc_event::kernel_event, "none");
return *sc->m_none_event;
}

private:

Expand Down
4 changes: 4 additions & 0 deletions src/sysc/kernel/sc_simcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ sc_simcontext::init()
m_method_invoker_p = NULL;
m_cor = 0;
m_reset_finder_q = 0;
m_none_event = NULL;
m_in_simulator_control = false;
m_start_of_simulation_called = false;
m_end_of_simulation_called = false;
Expand All @@ -370,6 +371,9 @@ sc_simcontext::clean()
// remove remaining zombie processes
do_collect_processes();

if (m_none_event)
delete m_none_event;

delete m_method_invoker_p;
delete m_error;
delete m_cor_pkg;
Expand Down
2 changes: 2 additions & 0 deletions src/sysc/kernel/sc_simcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ class SC_API sc_simcontext

sc_reset_finder* m_reset_finder_q; // Q of reset finders to reconcile.

sc_event* m_none_event; // never notified event

private:

// disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tlm_event_finder_t<IF,T>::find_event( sc_core::sc_interface* if_p ) const
dynamic_cast<const IF*>( port().get_interface() );
if( iface == 0 ) {
report_error( sc_core::SC_ID_FIND_EVENT_, "port is not bound" );
return sc_core::sc_event::none;
return sc_core::sc_event::none();
}
return (const_cast<IF*>( iface )->*m_event_method) ( 0 );
}
Expand Down

0 comments on commit 1292c02

Please sign in to comment.