51class sc_sync_window :
public sc_core::sc_module,
public sc_core::sc_prim_channel
53 static_assert(std::is_base_of<sc_sync_policy_base, sc_sync_policy>::value,
54 "sc_sync_policy must derive from sc_sync_policy_base");
56 sc_core::sc_event m_sweep_ev;
64 sc_core::sc_time from;
69 static inline const struct window zero_window = { sc_core::SC_ZERO_TIME, sc_core::SC_ZERO_TIME };
70 static inline const struct window open_window = { sc_core::SC_ZERO_TIME, sc_core::sc_max_time() };
74 window m_incomming_window;
77 std::function<
void(
const window&)> m_other_async_set_window_fn;
79 void do_other_async_set_window_fn(window w)
81 if (m_other_async_set_window_fn) {
82 auto now = sc_core::sc_time_stamp();
83 m_other_async_set_window_fn(w);
90 auto now = sc_core::sc_time_stamp();
91 auto to = m_window.to;
93 <<
" their window " << m_window.from <<
" " << to;
96 sc_core::sc_unsuspend_all();
99 SCP_TRACE(()) <<
"Suspend at: " <<
now <<
" quantum: " << policy.quantum();
100 do_other_async_set_window_fn({
now,
now + policy.quantum() });
102 if (!policy.keep_alive()) async_attach_suspending();
103 sc_core::sc_suspend_all();
106 sc_core::sc_unsuspend_all();
107 if (!policy.keep_alive()) async_detach_suspending();
110 m_step_ev.notify(to -
now);
119 auto now = sc_core::sc_time_stamp();
122 <<
" their window " << m_window.from <<
" - " << m_window.to;
124 do_other_async_set_window_fn({
now,
now + policy.quantum() });
130 std::lock_guard<std::mutex>
lg(m_mutex);
132 m_window = m_incomming_window;
133 auto now = sc_core::sc_time_stamp();
135 <<
" their window " << m_window.from <<
" - " << m_window.to;
137 if (m_window.from >
now) {
138 m_sweep_ev.notify(m_window.from -
now);
143 m_update_ev.notify(sc_core::SC_ZERO_TIME);
154 void async_set_window(
const window& w)
157 std::lock_guard<std::mutex>
lg(m_mutex);
158 m_incomming_window = w;
159 if (!(w == m_window)) {
160 SCP_INFO(()) <<
"sync " << w.from <<
" " << w.to;
166 async_detach_suspending();
167 m_other_async_set_window_fn(open_window);
169 void bind(sc_sync_window*
other)
171 if (m_other_async_set_window_fn) {
173 "m_other_async_set_window_fn was already registered or other "
174 "sc_sync_window was already bound!");
176 m_other_async_set_window_fn = std::bind(&sc_sync_window::async_set_window,
other, std::placeholders::_1);
178 void register_sync_cb(std::function<
void(
const window&)>
fn)
180 if (m_other_async_set_window_fn) {
182 "m_other_async_set_window_fn was already registered or other "
183 "sc_sync_window was already bound!");
185 m_other_async_set_window_fn =
fn;
187 SC_CTOR (sc_sync_window) : m_window({sc_core::SC_ZERO_TIME, policy.quantum()})
198 m_step_ev.notify(sc_core::SC_ZERO_TIME);
200 this->sc_core::sc_prim_channel::async_attach_suspending();