|
VLink
2.0.0
A high-performance communication middleware
|
Bounded lock-free multi-producer multi-consumer ring buffer with optional cv blocking. More...
#include <array>#include <atomic>#include <chrono>#include <cstddef>#include <limits>#include <memory>#include <mutex>#include <new>#include <utility>#include "./condition_variable.h"#include "./macros.h"#include "./utils.h"Go to the source code of this file.
Classes | |
| class | vlink::MpmcQueueBase |
| Non-template base class that owns every element-type-independent piece of state. More... | |
| struct | vlink::MpmcQueueBase::QuitFlag |
| class | vlink::MpmcQueue< T > |
Fixed-capacity lock-free MPMC ring buffer over T. More... | |
Namespaces | |
| vlink | |
Macros | |
| #define | VLINK_NO_INSTRUMENT |
Bounded lock-free multi-producer multi-consumer ring buffer with optional cv blocking.
MpmcQueue is a fixed-capacity ring buffer based on a turn-counter algorithm. Each slot holds a per-slot atomic turn counter that encodes whether the slot is currently empty (ready for a producer) or full (ready for a consumer).
head_ to claim a slot and spin until chunk.turn == turn(head) * 2 (slot empty), then construct the value and publish turn = turn(head) * 2 + 1 (slot full).tail_ to claim a slot and spin until chunk.turn == turn(tail) * 2 + 1 (slot full), then move the value out and publish turn = turn(tail) * 2 + 2 (slot empty for next round).kFirstSpinTimes (32) iterations before calling yield_cpu.head_, tail_ and each Chunk live in dedicated 64-byte regions to avoid false sharing.| Behaviour | Push contract | Pop contract |
|---|---|---|
kNoBehavior | No notification on success or failure | Spin-wait only |
kConditionBehavior | Acquire cv_mtx_, notify not_empty | Wake not_full waiter on pop |
| Blocking variants | emplace / push spin until success | pop spins until a slot is full |
| Non-blocking variants | try_emplace / try_push return on full | try_pop returns false on empty |
| Quit signal | notify_to_quit drops further pushes | Pop returns without value once quit set |
emplace / pop block by spinning; for bounded producers prefer the try_* forms. Capacity must be >= 1 (otherwise std::invalid_argument is thrown). notify_to_quit gracefully drains pending waiters and silently drops further pushes. | #define VLINK_NO_INSTRUMENT |