Lock-free bounded MPMC ring buffer.
More...
#include <mpmc_queue.hpp>
|
| | MpmcQueue (size_t min_capacity) |
| | Construct a queue with at least min_capacity slots.
|
| | ~MpmcQueue () |
| | MpmcQueue (const MpmcQueue &)=delete |
| MpmcQueue & | operator= (const MpmcQueue &)=delete |
| | MpmcQueue (MpmcQueue &&)=delete |
| MpmcQueue & | operator= (MpmcQueue &&)=delete |
| bool | try_push (T &&data) |
| | Try to enqueue an item (non-blocking, move semantics).
|
| bool | try_push (const T &data) |
| | Try to enqueue an item (copy overload).
|
| bool | try_pop (T &data) |
| | Try to dequeue an item (non-blocking).
|
| size_t | size_approx () const noexcept |
| | Approximate number of items currently in the queue.
|
| bool | empty_approx () const noexcept |
| | Return true if the queue appears empty (approximate).
|
| size_t | capacity () const noexcept |
| | Actual slot capacity (always a power of two).
|
template<typename T>
class libe3::MpmcQueue< T >
Lock-free bounded MPMC ring buffer.
- Template Parameters
-
| T | Element type. Must be default-constructible and movable. |
Usage:
if (!q.try_push(std::move(msg))) {
MyMsg out;
if (q.try_pop(out)) {
MpmcQueue(size_t min_capacity)
Construct a queue with at least min_capacity slots.
Definition at line 48 of file mpmc_queue.hpp.
◆ MpmcQueue() [1/3]
Construct a queue with at least min_capacity slots.
The actual capacity is rounded up to the next power of two (minimum 2).
- Parameters
-
| min_capacity | Minimum number of slots (0 is treated as 1). |
Definition at line 56 of file mpmc_queue.hpp.
◆ ~MpmcQueue()
◆ MpmcQueue() [2/3]
◆ MpmcQueue() [3/3]
◆ capacity()
Actual slot capacity (always a power of two).
Definition at line 178 of file mpmc_queue.hpp.
◆ empty_approx()
Return true if the queue appears empty (approximate).
Definition at line 175 of file mpmc_queue.hpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ size_approx()
Approximate number of items currently in the queue.
Due to concurrent modifications this value may be slightly stale, but is always in [0, capacity()].
Definition at line 168 of file mpmc_queue.hpp.
◆ try_pop()
Try to dequeue an item (non-blocking).
- Parameters
-
| [out] | data | Receives the dequeued item on success. |
- Returns
- true on success; false if the queue is empty.
Definition at line 134 of file mpmc_queue.hpp.
◆ try_push() [1/2]
Try to enqueue an item (copy overload).
Definition at line 124 of file mpmc_queue.hpp.
◆ try_push() [2/2]
Try to enqueue an item (non-blocking, move semantics).
- Returns
- true on success; false if the queue is full.
Definition at line 94 of file mpmc_queue.hpp.
The documentation for this class was generated from the following file: