CppCommon
1.0.4.1
C++ Common Library
|
Multiple producers / single consumer wait-free ring buffer. More...
#include <mpsc_ring_buffer.h>
Public Member Functions | |
MPSCRingBuffer (size_t capacity, size_t concurrency=std::thread::hardware_concurrency()) | |
Default class constructor. More... | |
MPSCRingBuffer (const MPSCRingBuffer &)=delete | |
MPSCRingBuffer (MPSCRingBuffer &&)=delete | |
~MPSCRingBuffer ()=default | |
MPSCRingBuffer & | operator= (const MPSCRingBuffer &)=delete |
MPSCRingBuffer & | operator= (MPSCRingBuffer &&)=delete |
operator bool () const noexcept | |
Check if the buffer is not empty. More... | |
bool | empty () const noexcept |
Is ring buffer empty? More... | |
size_t | capacity () const noexcept |
Get ring buffer capacity. More... | |
size_t | concurrency () const noexcept |
Get ring buffer concurrency. More... | |
size_t | size () const noexcept |
Get ring buffer size. More... | |
bool | Enqueue (const void *data, size_t size) |
Enqueue a data into the ring buffer (single producer thread method) More... | |
bool | Dequeue (void *data, size_t &size) |
Dequeue a data from the ring buffer (single consumer thread method) More... | |
Multiple producers / single consumer wait-free ring buffer.
Multiple producers / single consumer wait-free ring buffer use only atomic operations to provide thread-safe enqueue and dequeue operations. This data structure consist of several SPSC ring buffers which count is provided as a hardware concurrency in the constructor. All of them are randomly accessed with a RDTS distribution index. All the items available in sesequential or batch mode. All ring buffer sizes are limited to the capacity provided in the constructor.
FIFO order is not guaranteed!
Thread-safe.
Definition at line 35 of file mpsc_ring_buffer.h.
|
inlineexplicit |
Default class constructor.
capacity | - Ring buffer capacity (must be a power of two) |
concurrency | - Hardware concurrency (default is std::thread::hardware_concurrency) |
Definition at line 11 of file mpsc_ring_buffer.inl.
|
delete |
|
delete |
|
default |
|
inlinenoexcept |
Get ring buffer capacity.
Definition at line 57 of file mpsc_ring_buffer.h.
|
inlinenoexcept |
Get ring buffer concurrency.
Definition at line 59 of file mpsc_ring_buffer.h.
|
inline |
Dequeue a data from the ring buffer (single consumer thread method)
The data will be copied from the ring buffer using 'memcpy()' function.
Will not block.
data | - Data buffer to dequeue |
size | - Data buffer size |
Definition at line 38 of file mpsc_ring_buffer.inl.
|
inlinenoexcept |
Is ring buffer empty?
Definition at line 55 of file mpsc_ring_buffer.h.
|
inline |
Enqueue a data into the ring buffer (single producer thread method)
The data will be copied into the ring buffer using 'memcpy()' function. Data size should not be greater than ring buffer capacity!
Will not block.
data | - Data buffer to enqueue |
size | - Data buffer size |
Definition at line 26 of file mpsc_ring_buffer.inl.
|
inlineexplicitnoexcept |
Check if the buffer is not empty.
Definition at line 52 of file mpsc_ring_buffer.h.
|
delete |
|
delete |
|
inlinenoexcept |
Get ring buffer size.
Definition at line 18 of file mpsc_ring_buffer.inl.