3535#include < string>
3636
3737namespace sc_core {
38- class sc_ob_event : public sc_core ::sc_module, public sc_core::sc_event, public sc_core::sc_stage_callback_if
39- {
38+ class sc_ob_event : public sc_core ::sc_module,
39+ public sc_core::sc_event,
40+ public sc_core::sc_stage_callback_if {
4041
4142private:
42- sc_core::sc_event m_update;
43- sc_core::sc_time m_scheduled;
44- sc_core::sc_process_handle m_th;
45-
46- void update_m ()
47- {
48- auto now = sc_core::sc_time_stamp ();
49- if (now >= m_scheduled) {
50- sc_core::sc_event::notify ();
51- } else {
52- sc_core::sc_time pending = now;
53- if (sc_core::sc_pending_activity_at_future_time ()) {
54- pending = now + sc_core::sc_time_to_pending_activity ();
55- }
56- if (pending >= m_scheduled) {
57- sc_core::sc_event::notify (m_scheduled - now);
58- } else {
59- if (pending > now) {
60- m_update.notify (pending - now);
61- } else {
62- sc_core::sc_register_stage_callback (*this , sc_core::SC_POST_UPDATE);
63- }
64- }
65- }
66- }
67-
68- void future_events_notify_th ()
69- {
70- while (true ) {
71- m_th.suspend ();
72- update_m ();
73- }
43+ sc_core::sc_time m_scheduled;
44+ sc_core::sc_process_handle m_th;
45+
46+ void future_events_notify_th () {
47+ while (true ) {
48+ m_th.suspend ();
49+
50+ auto now = sc_core::sc_time_stamp ();
51+ if (now >= m_scheduled) {
52+ sc_core::sc_event::notify ();
53+ } else {
54+ sc_core::sc_event::notify (m_scheduled - now);
55+ }
7456 }
57+ }
7558
7659public:
77- sc_ob_event (const sc_core::sc_module_name& n = sc_core::sc_gen_unique_name(" sc_ob_event" ))
78- : sc_module(n)
79- , sc_core::sc_event((std::string(n) + " _notifier_event" ).c_str())
80- , m_update((std::string(n) + " _update_event" ).c_str())
81- , m_scheduled(sc_core::SC_ZERO_TIME)
82- {
83- SC_METHOD (update_m);
84- sensitive << m_update;
85- dont_initialize ();
86- SC_THREAD (future_events_notify_th);
87- m_th = sc_core::sc_get_current_process_handle ();
88- }
89- void notify ()
90- {
91- m_scheduled = sc_core::sc_time_stamp ();
92- m_update.notify (sc_core::SC_ZERO_TIME);
93- }
94- void notify (double delay, sc_core::sc_time_unit unit)
95- {
96- m_scheduled = sc_core::sc_time_stamp () + sc_core::sc_time (delay, unit);
97- m_update.notify (sc_core::SC_ZERO_TIME);
98- }
99- void notify (sc_core::sc_time delay)
100- {
101- m_scheduled = sc_core::sc_time_stamp () + delay;
102- m_update.notify (sc_core::SC_ZERO_TIME);
103- }
104-
105- void stage_callback (const sc_core::sc_stage& stage)
106- {
107- if (sc_core::sc_pending_activity_at_future_time ()) {
108- m_th.resume ();
109- sc_core::sc_unregister_stage_callback (*this , sc_core::SC_POST_UPDATE);
110- }
111- }
112-
113- ~sc_ob_event () {}
60+ sc_ob_event (const sc_core::sc_module_name &n =
61+ sc_core::sc_gen_unique_name (" sc_ob_event" ))
62+ : sc_module(n), m_scheduled(sc_core::SC_ZERO_TIME) {
63+ SC_THREAD (future_events_notify_th);
64+ m_th = sc_core::sc_get_current_process_handle ();
65+ }
66+ void notify () {
67+ sc_core::sc_event::notify ();
68+ sc_core::sc_unregister_stage_callback (*this , sc_core::SC_POST_UPDATE);
69+ }
70+ void notify (double delay, sc_core::sc_time_unit unit) {
71+ notify (sc_core::sc_time (delay, unit));
72+ }
73+ void notify (sc_core::sc_time delay) {
74+ sc_core::sc_event::cancel ();
75+ m_scheduled = sc_core::sc_time_stamp () + delay;
76+ sc_core::sc_register_stage_callback (*this , sc_core::SC_POST_UPDATE);
77+ }
78+
79+ void stage_callback (const sc_core::sc_stage &stage) {
80+ // if (sc_core::sc_pending_activity()) { // should the event fire is there is pending activity, or if we arrive at the time?
81+ sc_core::sc_time pending = sc_core::sc_time_stamp ();
82+ if (sc_core::sc_pending_activity_at_future_time ()) {
83+ pending += sc_core::sc_time_to_pending_activity ();
84+ }
85+
86+ if (pending >= m_scheduled) {
87+ m_th.resume ();
88+ sc_core::sc_unregister_stage_callback (*this , sc_core::SC_POST_UPDATE);
89+ }
90+ // }
91+ }
92+
93+ ~sc_ob_event () {}
11494};
115- } // namespace
95+ } // namespace sc_core
11696
11797#endif // _SC_OB_EVENT_
0 commit comments