33 std::array<char,
SPSC_CACHELINE -
sizeof(head) -
sizeof(wrap_head) -
sizeof(producer_blocked)> _pad0;
47static_assert(
alignof(
SpscCtrl) == SPSC_CACHELINE,
"SpscCtrl alignment");
48static_assert(
sizeof(
SpscCtrl) % SPSC_CACHELINE == 0,
"SpscCtrl size multiple of cache line");
78 static SpscShm create(
const std::string& name,
size_t min_capacity);
85 static SpscShm connect(
const std::string& name);
92 static bool unlink(
const std::string& name);
103 uint64_t available()
const;
105 uint64_t
capacity()
const {
return ctrl_->capacity; }
118 void* claim(
size_t want, uint32_t timeout_ns);
127 void publish(
size_t n);
140 void* peek(
size_t want, uint32_t timeout_ns);
149 void release(
size_t n);
159 bool wait_for_data(
size_t need, uint32_t spin_ns);
160 bool wait_for_space(
size_t need, uint32_t spin_ns);
166 void debug_dump(
const char* prefix)
const;
175 uint8_t* buf_ =
nullptr;
176 bool previous_had_data_ =
false;
177 bool previous_had_space_ =
false;
Lock-free single-producer single-consumer shared memory ring buffer.
SpscShm(const SpscShm &)=delete
uint64_t capacity() const
SpscShm & operator=(const SpscShm &)=delete
constexpr size_t SPSC_CACHELINE
Control structure for SPSC ring buffer.
std::atomic< bool > consumer_blocked
std::array< char, SPSC_CACHELINE - sizeof(tail) - sizeof(consumer_blocked)> _pad1
std::atomic< bool > producer_blocked