13struct async_thread : sc_core::sc_prim_channel {
16 : sc_core::sc_prim_channel{sc_core::sc_gen_unique_name(
"async_thread")} {}
18 explicit async_thread(
const char* nm)
19 : sc_core::sc_prim_channel{nm} {}
26 void start(std::function<sc_core::sc_time()>
const& f) {
27 SCCTRACE(SCOBJ) <<
"Starting new thread";
28 t1 = std::move(std::thread([
this, f]() {
30 finish_time.store(f().value());
31 async_request_update();
32 }
catch(std::future_error& e) {
38 const sc_core::sc_event& thread_finish_event()
const {
return finish_event; }
41 void update()
override {
43 auto end_time = sc_core::sc_time::from_value(finish_time.load());
44 finish_event.notify(end_time > sc_core::sc_time_stamp() ? end_time - sc_core::sc_time_stamp() : sc_core::SC_ZERO_TIME);
46 SCCTRACE(SCOBJ) <<
"Finished execution of thread";
49 sc_core::sc_event finish_event;
50 std::atomic<uint64_t> finish_time;