scc 2025.09
SystemC components library
async_queue.h
1#pragma once
2
3#include <rigtorp/SPSCQueue.h>
4#include <sysc/communication/sc_prim_channel.h>
5#include <systemc>
6
7namespace scc {
8template <typename T> struct async_source_if : virtual public sc_core::sc_interface {
9 virtual bool try_get(T& v) = 0;
10 virtual sc_core::sc_event const& data_event() const = 0;
11};
12
13template <typename T> struct async_queue : sc_core::sc_prim_channel, async_source_if<T> {
14
15 async_queue(unsigned size = 16)
16 : que{size} {}
17
18 explicit async_queue(const char* nm, unsigned size = 16)
19 : sc_core::sc_prim_channel{nm}
20 , que{size} {}
21
22 void push(T const& v) {
23 que.push(v);
24 async_request_update();
25 }
26
27 void emplace(T&& v) {
28 que.emplace(std::move(v));
29 pending_update.store(true, std::memory_order_release);
30 async_request_update();
31 }
32
33 bool try_get(T& v) override {
34 if(!que.empty()) {
35 if(auto f = que.front()) {
36 v = std::move(*f);
37 que.pop();
38 return true;
39 }
40 }
41 return false;
42 }
43
44 const sc_core::sc_event& data_event() const override { return ev_; }
45
46private:
47 void update() override {
48 if(pending_update.exchange(false, std::memory_order_acq_rel))
49 ev_.notify(sc_core::SC_ZERO_TIME);
50 }
52 sc_core::sc_event ev_;
53 std::atomic<bool> pending_update{false};
54};
55} // namespace scc
SCC TLM utilities.