template<typename T>
TrinyxMPSCRing class
TrinyxMPSCRing<T> — Bounded MPSC lock-free queue (Vyukov sequence-number pattern).
- Multiple producers may call TryPush concurrently (CAS on EnqueuePos).
- Exactly one consumer owns the read side via a Consumer handle. Consumer::
TryPop / TryPeekAt / Size / DropFront are the only read interfaces. DequeuePos lives in the Consumer as a plain size_t — no atomics, no CAS. - Capacity is rounded up to the next power of 2 by Initialize().
- MakeConsumer() may only be called once (asserted in debug).
Overwrite semantics (OverwritePush): When the ring is full, OverwritePush evicts the oldest entry and writes the new item in its place, so the Consumer always sees the most recent Capacity frames. OverwritePush is SP-only (single-producer). When it evicts, it increments OverflowCount; the Consumer syncs DequeuePos from this counter before each read.
Typical usage: // Owner thread (e.g. World): TrinyxMPSCRing<NetInputFrame> InputQueue; InputQueue.Initialize(128); auto Consumer = InputQueue.MakeConsumer(); // hand to net thread
// Single producer thread (e.g. LogicThread): InputQueue.OverwritePush(frame); // sliding-window semantics
// Net thread only (via Consumer handle): for (size_t i = 0; i < Consumer.Size(); ++i) { ... Consumer.TryPeekAt(i, f); } Consumer.DropFront(ackedCount);
See TrinyxRingBase for the full queue family overview.
Base classes
-
template<typename Derived, typename T>class TrinyxRingBase<TrinyxMPSCRing<T>, T>
Public types
- class Consumer
Constructors, destructors, conversion operators
- TrinyxMPSCRing() defaulted
- ~TrinyxMPSCRing()
- TrinyxMPSCRing(const TrinyxMPSCRing&) deleted
Public functions
- auto operator=(const TrinyxMPSCRing&) -> TrinyxMPSCRing& deleted
- auto Initialize(size_t requestedCapacity) -> bool
- void Shutdown()
- auto MakeConsumer() -> Consumer
- Issue the single Consumer handle. May only be called once per instance.
- auto TryPush(const T& item) -> bool
- auto TryPush(T&& item) -> bool
- auto OverwritePush(const T& item) -> bool
Function documentation
template<typename T>
bool TrinyxMPSCRing<T>:: OverwritePush(const T& item)
Single-producer overwrite push. When the ring is full, the oldest entry is silently evicted so the new item always lands. The Consumer syncs via OverflowCount on its next read and fast-forwards DequeuePos accordingly.
SP-ONLY: must be called from a single producer thread. Multiple concurrent callers will race on the eviction and corrupt the ring.
Returns true if an eviction occurred (informational).