From 86b051473210a20dd6f86f3b606175a239080bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Tue, 22 Sep 2020 12:38:30 +0200 Subject: [PATCH] sc_process_handle::non_event - convert from global variable to function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to sc_event::none, sc_process_handle::non_event is a global sc_event which holds a reference to the simulation context. Thereby complicating reset of this context as discussed in #8. This commit couples the sc_process_handle::non_event with the simulation context, thereby easing resets of the latter. At the time of writing, it is unclear to me whether it is strictly necessary to use different sc_event members in sc_simcontext for sc_event::none and sc_process_handle::non_event. Signed-off-by: Sören Tempel --- src/sysc/kernel/sc_process.cpp | 9 ++++++++- src/sysc/kernel/sc_process_handle.h | 10 +++++----- src/sysc/kernel/sc_simcontext.cpp | 4 ++++ src/sysc/kernel/sc_simcontext.h | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/sysc/kernel/sc_process.cpp b/src/sysc/kernel/sc_process.cpp index bc3c12ad1..66bdefa6c 100644 --- a/src/sysc/kernel/sc_process.cpp +++ b/src/sysc/kernel/sc_process.cpp @@ -47,7 +47,14 @@ namespace sc_core { std::vector sc_process_handle::empty_event_vector; std::vector sc_process_handle::empty_object_vector; -sc_event sc_process_handle::non_event( sc_event::kernel_event ); + +// If m_target_p == 0. +sc_event &sc_process_handle::non_event(void) const { + sc_simcontext *sc = sc_get_curr_simcontext(); + if (!sc->m_non_event) + sc->m_non_event = new sc_event(sc_event::kernel_event); + return *sc->m_non_event; +} // Last process that was created: diff --git a/src/sysc/kernel/sc_process_handle.h b/src/sysc/kernel/sc_process_handle.h index a70fe0702..cc299646e 100644 --- a/src/sysc/kernel/sc_process_handle.h +++ b/src/sysc/kernel/sc_process_handle.h @@ -147,9 +147,9 @@ class SC_API sc_process_handle { sc_process_b* m_target_p; // Target for this object instance. protected: - static std::vector empty_event_vector; // If m_target_p == 0. - static std::vector empty_object_vector; // If m_target_p == 0. - static sc_event non_event; // If m_target_p == 0. + static std::vector empty_event_vector; // If m_target_p == 0. + static std::vector empty_object_vector; // If m_target_p == 0. + sc_event& non_event(void) const; // If m_target_p == 0. }; inline bool operator == ( @@ -401,7 +401,7 @@ inline sc_event& sc_process_handle::reset_event() const else { SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "reset()"); - return sc_process_handle::non_event; + return sc_process_handle::non_event(); } } @@ -478,7 +478,7 @@ inline sc_event& sc_process_handle::terminated_event() else { SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "terminated_event()"); - return sc_process_handle::non_event; + return sc_process_handle::non_event(); } } diff --git a/src/sysc/kernel/sc_simcontext.cpp b/src/sysc/kernel/sc_simcontext.cpp index 6f7b398d0..fbc38d8f7 100644 --- a/src/sysc/kernel/sc_simcontext.cpp +++ b/src/sysc/kernel/sc_simcontext.cpp @@ -359,6 +359,7 @@ sc_simcontext::init() m_cor = 0; m_reset_finder_q = 0; m_none_event = NULL; + m_non_event = NULL; m_in_simulator_control = false; m_start_of_simulation_called = false; m_end_of_simulation_called = false; @@ -399,6 +400,9 @@ sc_simcontext::clean() m_reset_finder_q = rf->m_next_p; delete rf; } + + if (m_non_event) + delete m_non_event; } diff --git a/src/sysc/kernel/sc_simcontext.h b/src/sysc/kernel/sc_simcontext.h index edde987fe..2911b9a79 100644 --- a/src/sysc/kernel/sc_simcontext.h +++ b/src/sysc/kernel/sc_simcontext.h @@ -400,6 +400,7 @@ 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 + sc_event* m_non_event; // used by sc_process_handle if m_target_p == 0 private: