Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Thread-safe lock-free single-producer single-consumer circular buffer of copyable objects. More...
#include <spsc_ring_buffer.h>
Public Member Functions | |
SpscRingBuffer (IArena &arena, size_t n_elements) | |
Initialize. More... | |
~SpscRingBuffer () | |
Deinitialize. More... | |
bool | is_valid () const |
Check that allocation succeeded. More... | |
bool | is_empty () const |
Check if buffer is empty. More... | |
bool | push_back (const T &element) |
Append element to the end of the buffer. If buffer is full, drops element and returns false. Should be called from writer thread. Lock-free. More... | |
bool | pop_front (T &element) |
Fetch element from the beginning of the buffer. If buffer is empty, returns false. Should be called from reader thread. Lock-free. More... | |
Thread-safe lock-free single-producer single-consumer circular buffer of copyable objects.
Allows access from two concurrent threads: writer and reader. Both writer and reader are never blocked. Provides sequential consistency.
T | defines object type, it should be copyable. |
Implemented on top of SpscByteBuffer.
Definition at line 33 of file spsc_ring_buffer.h.
|
inline |
Initialize.
Definition at line 36 of file spsc_ring_buffer.h.
|
inline |
Deinitialize.
Definition at line 41 of file spsc_ring_buffer.h.
|
inline |
Check if buffer is empty.
Definition at line 54 of file spsc_ring_buffer.h.
|
inline |
Check that allocation succeeded.
Definition at line 49 of file spsc_ring_buffer.h.
|
inline |
Fetch element from the beginning of the buffer. If buffer is empty, returns false. Should be called from reader thread. Lock-free.
Definition at line 79 of file spsc_ring_buffer.h.
|
inline |
Append element to the end of the buffer. If buffer is full, drops element and returns false. Should be called from writer thread. Lock-free.
Definition at line 62 of file spsc_ring_buffer.h.