1#ifndef __SCC_TLM_QK_GLOBAL_TIME_KEEPER_H__
2#define __SCC_TLM_QK_GLOBAL_TIME_KEEPER_H__
22struct global_time_keeper {
23 friend class sc_time_syncronizer;
34 static global_time_keeper&
get() {
35 static global_time_keeper keeper;
58 client_coms_channels[idx].client2time_keeper.push(std::move(
comms_entry{tick, std::move(callback_task())}));
59 update_it.store(
true);
60 std::unique_lock<std::mutex> lk(upd_mtx);
70 inline void schedule_task(
size_t idx, std::packaged_task<sc_core::sc_time(
void)>&& task, uint64_t when) {
71 client_coms_channels[idx].client2time_keeper.push(std::move(
comms_entry{when, std::move(task)}));
72 update_it.store(
true);
73 std::unique_lock<std::mutex> lk(upd_mtx);
88 sc_coms_channel.client2time_keeper.push(std::move(
comms_entry{tick, std::move(callback_task())}));
89 update_it.store(
true);
90 std::unique_lock<std::mutex> lk(upd_mtx);
105 size_t get_channel_index();
107 void sync_local_times();
109 std::atomic<bool> stop_it{
false};
110 std::atomic<bool> update_it{
false};
111 std::atomic_uint64_t client_min_time;
112 std::atomic_uint64_t client_max_time;
113 std::atomic_uint64_t sc_kernel_time;
115 std::condition_variable update;
116 thread_comms_channel sc_coms_channel{-1ULL};
117 std::deque<thread_comms_channel> client_coms_channels;
119 bool started =
false;
the global time keeper, a singleton
uint64_t get_client_max_time_ticks(size_t idx)
Get the maximum time ticks a client thread is allowed to advance.
void update_client_time_ticks(size_t idx, uint64_t tick)
updates the global time keeper with the local time ticks of a clinet thread
uint64_t get_sc_time_ticks()
Get the maximum sc time ticks a client thread is allowed to advance.
static global_time_keeper & get()
the singleton getter
void update_sc_time_ticks(uint64_t tick)
updates the global time keeper with the local time ticks of the SystemC thread
uint64_t get_client_min_time_ticks()
Get the minimum time ticks of all client threads (not SystemC).
void schedule_task(size_t idx, std::packaged_task< sc_core::sc_time(void)> &&task, uint64_t when)
updates the global time keeper with the local time ticks of a clinet thread and schedules a task at t...
const sc_core::sc_time sc_time_step
the maximum timestep the simulator is allowed to do if there are no future events