|
| | MpmcRing (size_t capacity) |
| | Construct a ring buffer with the given capacity.
|
| |
| | MpmcRing (const MpmcRing &)=delete |
| |
| MpmcRing & | operator= (const MpmcRing &)=delete |
| |
| | MpmcRing (MpmcRing &&)=delete |
| |
| MpmcRing & | operator= (MpmcRing &&)=delete |
| |
| bool | push (T val) noexcept(std::is_nothrow_move_assignable_v< T >) |
| | Push an element into the ring (non-blocking).
|
| |
| bool | pop (T &out) noexcept(std::is_nothrow_move_assignable_v< T >) |
| | Pop an element from the ring (non-blocking).
|
| |
| size_t | capacity () const noexcept |
| | Return the actual ring capacity (always a power of two).
|
| |
| size_t | size () const noexcept |
| | Approximate occupancy (not linearizable without external synchronization).
|
| |
| bool | empty () const noexcept |
| | Check whether the ring appears empty (approximate).
|
| |
template<typename T>
class signet::forge::MpmcRing< T >
Lock-free bounded multi-producer multi-consumer ring buffer.
Based on Dmitry Vyukov's bounded MPMC queue algorithm (public domain). Multiple producers and consumers call push()/pop() concurrently without external locking. O(1) amortized push/pop, no allocation after construction, ABA-safe via per-slot sequence numbers.
Each slot carries a sequence number encoding its lifecycle phase:
seq == pos : slot is empty; a producer at pos may claim it.
seq == pos + 1 : slot is full; a consumer at pos may drain it.
seq == pos + cap: slot has been drained and is ready for the next cycle.
- Template Parameters
-
| T | Element type. Must be move-assignable. |
- Note
- Non-copyable and non-movable (contains atomics).
-
Runtime capacity is always rounded up to the next power of two (minimum 2).
- See also
- EventBus
Definition at line 46 of file mpmc_ring.hpp.