CppCommon
1.0.4.1
C++ Common Library
|
Multiple producers / single consumer wait-free ring queue. More...
#include <mpsc_ring_queue.h>
Public Member Functions | |
MPSCRingQueue (size_t capacity, size_t concurrency=std::thread::hardware_concurrency()) | |
Default class constructor. More... | |
MPSCRingQueue (const MPSCRingQueue &)=delete | |
MPSCRingQueue (MPSCRingQueue &&)=delete | |
~MPSCRingQueue ()=default | |
MPSCRingQueue & | operator= (const MPSCRingQueue &)=delete |
MPSCRingQueue & | operator= (MPSCRingQueue &&)=delete |
operator bool () const noexcept | |
Check if the queue is not empty. More... | |
bool | empty () const noexcept |
Is ring queue empty? More... | |
size_t | capacity () const noexcept |
Get ring queue capacity. More... | |
size_t | concurrency () const noexcept |
Get ring queue concurrency. More... | |
size_t | size () const noexcept |
Get ring queue size. More... | |
bool | Enqueue (const T &item) |
Enqueue an item into the ring queue (multiple producers threads method) More... | |
bool | Enqueue (T &&item) |
Enqueue an item into the ring queue (multiple producers threads method) More... | |
bool | Dequeue (T &item) |
Dequeue an item from the ring queue (single consumer threads method) More... | |
bool | Dequeue (const std::function< void(const T &)> &handler=[](const int &){}) |
Dequeue all items from the linked queue (single consumer thread method) More... | |
Multiple producers / single consumer wait-free ring queue.
Multiple producers / single consumer wait-free ring queue use only atomic operations to provide thread-safe enqueue and dequeue operations. This data structure consist of several SPSC ring queues 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 queue sizes are limited to the capacity provided in the constructor.
FIFO order is not guaranteed!
Thread-safe.
Definition at line 39 of file mpsc_ring_queue.h.
|
inlineexplicit |
Default class constructor.
capacity | - Ring queue capacity (must be a power of two) |
concurrency | - Hardware concurrency (default is std::thread::hardware_concurrency) |
Definition at line 12 of file mpsc_ring_queue.inl.
|
delete |
|
delete |
|
default |
|
inlinenoexcept |
Get ring queue capacity.
Definition at line 61 of file mpsc_ring_queue.h.
|
inlinenoexcept |
Get ring queue concurrency.
Definition at line 63 of file mpsc_ring_queue.h.
|
inline |
Dequeue all items from the linked queue (single consumer thread method)
All items in the batcher will be processed by the given handler.
Will not block.
handler | - Batch handler (default is empty handler) |
Definition at line 62 of file mpsc_ring_queue.inl.
|
inline |
Dequeue an item from the ring queue (single consumer threads method)
The item will be moved from the ring queue.
Will not block.
item | - Item to dequeue |
Definition at line 49 of file mpsc_ring_queue.inl.
|
inlinenoexcept |
Is ring queue empty?
Definition at line 59 of file mpsc_ring_queue.h.
|
inline |
Enqueue an item into the ring queue (multiple producers threads method)
The item will be copied into the ring queue.
Will not block.
item | - Item to enqueue |
Definition at line 29 of file mpsc_ring_queue.inl.
|
inline |
Enqueue an item into the ring queue (multiple producers threads method)
The item will be moved into the ring queue.
Will not block.
item | - Item to enqueue |
Definition at line 36 of file mpsc_ring_queue.inl.
|
inlineexplicitnoexcept |
Check if the queue is not empty.
Definition at line 56 of file mpsc_ring_queue.h.
|
delete |
|
delete |
|
inlinenoexcept |
Get ring queue size.
Definition at line 20 of file mpsc_ring_queue.inl.