scc 2026.07
SystemC components library
sc_time_syncronizer.h
1#ifndef __SCC_TLM_QK_SC_TIME_SYNCRONIZER_H__
2#define __SCC_TLM_QK_SC_TIME_SYNCRONIZER_H__
3
4#include "global_time_keeper.h"
5#include <scc/peq.h>
6
7namespace tlm {
8namespace scc {
9namespace qk {
10struct client_deputy {
12 bool blocked;
13 client_deputy(char const* nm)
14 : peq{nm}
15 , blocked(false) {}
16};
17
21struct sc_time_syncronizer : sc_core::sc_stage_callback_if, sc_core::sc_process_host {
22 ~sc_time_syncronizer() = default;
28 static sc_time_syncronizer& get() {
29 static sc_time_syncronizer keeper(global_time_keeper::get());
30 return keeper;
31 }
32
40 auto idx = gtk.get_channel_index();
41 client_deputies.emplace_back();
42 auto& client = client_deputies[client_deputies.size() - 1];
43 sc_core::sc_spawn(
44 [this, &client, idx]() {
45 while(true) {
46 client.peq.get()();
47 if(!client.peq.has_next())
48 this->notify_client_blocked(idx, false);
49 }
50 },
51 sc_core::sc_gen_unique_name("peq_cb", false));
52
53 return idx;
54 }
55
56 inline void notify_client_blocked(size_t idx, bool is_blocked) {
57 assert(idx < client_deputies.size());
58 client_deputies[idx].blocked = is_blocked;
59 sc_is_free_running =
60 !std::any_of(std::begin(client_deputies), std::end(client_deputies), [](client_deputy const& d) { return !d.blocked; });
61#ifdef DEBUG_MT_SCHEDULING
62 SCCTRACEALL(__PRETTY_FUNCTION__) << (is_blocked ? "blocking" : "unblocking") << " thread " << idx
63 << ", sc_is_free_running=" << sc_is_free_running;
64#endif
65 }
66
67private:
68 enum class sync_state { INITIAL, PROCESSING, ARMED };
69 sc_time_syncronizer(global_time_keeper& gtk);
70 void sc_method();
71 bool process_pending_tasks();
72 sync_state state{sync_state::INITIAL};
73 void stage_callback(const sc_core::sc_stage& stage) override;
74 inline void notify_task(size_t idx, callback_task&& task, sc_core::sc_time const& d) {
75 client_deputies[idx].peq.notify(std::move(task), d);
76 notify_client_blocked(idx, true);
77 }
78 sc_core::sc_time get_min_time() { return sc_core::sc_time::from_value(gtk.get_client_min_time_ticks()); }
79
80 global_time_keeper& gtk;
81 sc_core::sc_vector<client_deputy> client_deputies;
82 sc_core::sc_process_handle method_handle;
83 bool sc_is_free_running{true};
84};
85} // namespace qk
86} // namespace scc
87} // namespace tlm
88#endif // __SCC_TLM_QK_SC_TIME_SYNCRONIZER_H__
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19
priority event queue
Definition peq.h:42
static global_time_keeper & get()
the singleton getter
static sc_time_syncronizer & get()
the singleton getter
size_t get_channel_index()
Get the channel index.