CppCommon
1.0.4.1
C++ Common Library
|
Single producer / single consumer wait-free ring queue. More...
#include <spsc_ring_queue.h>
Public Member Functions | |
SPSCRingQueue (size_t capacity) | |
Default class constructor. More... | |
SPSCRingQueue (const SPSCRingQueue &)=delete | |
SPSCRingQueue (SPSCRingQueue &&)=delete | |
~SPSCRingQueue () | |
SPSCRingQueue & | operator= (const SPSCRingQueue &)=delete |
SPSCRingQueue & | operator= (SPSCRingQueue &&)=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 | size () const noexcept |
Get ring queue size. More... | |
bool | Enqueue (const T &item) |
Enqueue an item into the ring queue (single producer thread method) More... | |
bool | Enqueue (T &&item) |
Enqueue an item into the ring queue (single producer thread method) More... | |
bool | Dequeue (T &item) |
Dequeue an item from the ring queue (single consumer thread method) More... | |
Single producer / single consumer wait-free ring queue.
Single producer / single consumer wait-free ring queue use only atomic operations to provide thread-safe enqueue and dequeue operations. Ring queue is bounded to the fixed capacity provided in the constructor.
FIFO order is guaranteed!
Thread-safe.
A combination of the algorithms described by the circular buffers documentation found in the Linux kernel, and the bounded MPMC queue by Dmitry Vyukov. Implemented in pure C++11. Should work across most CPU architectures. http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
Definition at line 34 of file spsc_ring_queue.h.
|
inlineexplicit |
Default class constructor.
capacity | - Ring queue capacity (must be a power of two) |
Definition at line 12 of file spsc_ring_queue.inl.
|
delete |
|
delete |
|
inline |
Definition at line 44 of file spsc_ring_queue.h.
|
inlinenoexcept |
Get ring queue capacity.
Definition at line 55 of file spsc_ring_queue.h.
|
inline |
Dequeue an item from the ring queue (single consumer thread method)
The item will be moved from the ring queue.
Will not block.
item | - Item to dequeue |
Definition at line 59 of file spsc_ring_queue.inl.
|
inlinenoexcept |
Is ring queue empty?
Definition at line 53 of file spsc_ring_queue.h.
|
inline |
Enqueue an item into the ring queue (single producer thread method)
The item will be copied into the ring queue.
Will not block.
item | - Item to enqueue |
Definition at line 33 of file spsc_ring_queue.inl.
|
inline |
Enqueue an item into the ring queue (single producer thread method)
The item will be moved into the ring queue.
Will not block.
item | - Item to enqueue |
Definition at line 40 of file spsc_ring_queue.inl.
|
inlineexplicitnoexcept |
Check if the queue is not empty.
Definition at line 50 of file spsc_ring_queue.h.
|
delete |
|
delete |
|
inlinenoexcept |
Get ring queue size.
Definition at line 24 of file spsc_ring_queue.inl.