12#ifndef ROC_CORE_SPSC_RING_BUFFER_H_
13#define ROC_CORE_SPSC_RING_BUFFER_H_
37 : byte_buf_(arena, sizeof(T), n_elements) {
42 while (
void* ptr = byte_buf_.begin_read()) {
43 static_cast<T*
>(ptr)->~T();
50 return byte_buf_.is_valid();
55 return byte_buf_.is_empty();
63 void* ptr = byte_buf_.begin_write();
70 byte_buf_.end_write();
80 void* ptr = byte_buf_.begin_read();
86 element = *
static_cast<T*
>(ptr);
87 static_cast<T*
>(ptr)->~T();
Thread-safe lock-free single-producer single-consumer circular buffer of byte chunks.
SpscRingBuffer(IArena &arena, size_t n_elements)
Initialize.
bool push_back(const T &element)
Append element to the end of the buffer. If buffer is full, drops element and returns false....
bool pop_front(T &element)
Fetch element from the beginning of the buffer. If buffer is empty, returns false....
~SpscRingBuffer()
Deinitialize.
bool is_valid() const
Check that allocation succeeded.
bool is_empty() const
Check if buffer is empty.
General-purpose building blocks and platform abstraction layer.
Single-producer single-consumer circular buffer of byte chunks.
Commonly used types and functions.