VLink  2.0.0
A high-performance communication middleware
vlink::MpmcQueue< T > 模板类 参考

Fixed-capacity lock-free MPMC ring buffer over T. 更多...

#include <mpmc_queue.h>

类 vlink::MpmcQueue< T > 继承关系图:
vlink::MpmcQueue< T > 的协作图:

Public 成员函数

 MpmcQueue (size_t capacity) VLINK_NO_INSTRUMENT
 Constructs a queue with the given fixed capacity. 更多...
 
 ~MpmcQueue () noexcept VLINK_NO_INSTRUMENT
 Destructor; destroys still-occupied slots and releases the chunk array. 更多...
 
template<Behavior BehaviorT = kNoBehavior, typename... Args>
void emplace (Args &&... args) noexcept VLINK_NO_INSTRUMENT
 In-place constructs an element and blocks until a slot is available. 更多...
 
template<Behavior BehaviorT = kNoBehavior, typename... Args>
bool try_emplace (Args &&... args) noexcept VLINK_NO_INSTRUMENT
 Non-blocking in-place construction. 更多...
 
template<Behavior BehaviorT = kNoBehavior, typename P >
void push (P &&v) noexcept VLINK_NO_INSTRUMENT
 Pushes a perfect-forwarded value, blocking until a slot is available. 更多...
 
template<Behavior BehaviorT = kNoBehavior, typename P >
bool try_push (P &&v) noexcept VLINK_NO_INSTRUMENT
 Non-blocking push wrapper around try_emplace. 更多...
 
template<Behavior BehaviorT = kNoBehavior>
void pop (T &v) noexcept VLINK_NO_INSTRUMENT
 Pops a value by move; blocks until an element is available. 更多...
 
template<Behavior BehaviorT = kNoBehavior>
bool try_pop (T &v) noexcept VLINK_NO_INSTRUMENT
 Non-blocking pop; returns false when the queue is empty. 更多...
 

额外继承的成员函数

 Per-call notification behaviour selector. 更多...

详细描述

template<typename T>
class vlink::MpmcQueue< T >

Fixed-capacity lock-free MPMC ring buffer over T.

Allocates capacity + 1 cache-line-aligned slots, validates alignment, and provides per-slot turn counters for non-blocking enqueue / dequeue. Element type must be movable.

模板参数
TElement type stored in each slot.

构造及析构函数说明

◆ MpmcQueue()

template<typename T >
vlink::MpmcQueue< T >::MpmcQueue ( size_t  capacity)
inlineexplicit

Constructs a queue with the given fixed capacity.

Details

Allocates capacity + 1 slots via the aligned allocator (extra trailing guard slot keeps index arithmetic simple). Validates that the allocation is aligned to kInterferenceSize bytes; misaligned allocations throw std::bad_alloc. Each slot's turn counter is default-initialised to zero.

参数
capacityMaximum number of elements; must be >= 1.
异常
std::invalid_argumentwhen capacity is below 1.
std::bad_allocwhen allocation fails or returns a misaligned pointer.
函数调用图:

◆ ~MpmcQueue()

template<typename T >
vlink::MpmcQueue< T >::~MpmcQueue
inlinenoexcept

Destructor; destroys still-occupied slots and releases the chunk array.

Not thread-safe with concurrent producers or consumers; the caller must quiesce the queue before destruction.

成员函数说明

◆ emplace()

template<typename T >
template<typename MpmcQueue< T >::Behavior BehaviorT, typename... Args>
void vlink::MpmcQueue< T >::emplace ( Args &&...  args)
inlinenoexcept

In-place constructs an element and blocks until a slot is available.

Claims the next slot via head_.fetch_add and spins on the turn counter until the slot is empty. When BehaviorT is kConditionBehavior the producer first awaits free space via wait_not_full and notifies one wait_not_empty waiter after publishing. Returns silently when notify_to_quit is observed.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
ArgsConstructor argument types forwarded to T.
参数
argsArguments forwarded to T 's constructor.
函数调用图:

◆ pop()

template<typename T >
template<typename MpmcQueue< T >::Behavior BehaviorT>
void vlink::MpmcQueue< T >::pop ( T &  v)
inlinenoexcept

Pops a value by move; blocks until an element is available.

Claims the next slot via tail_.fetch_add, spins until the slot is full, moves the value into v and republishes the slot as empty. When BehaviorT is kConditionBehavior a wait_not_full waiter is notified. Returns without altering v when notify_to_quit is observed mid-wait.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
参数
vDestination assigned via std::move.
函数调用图:

◆ push()

template<typename T >
template<typename MpmcQueue< T >::Behavior BehaviorT, typename P >
void vlink::MpmcQueue< T >::push ( P &&  v)
inlinenoexcept

Pushes a perfect-forwarded value, blocking until a slot is available.

Wrapper around emplace<BehaviorT>(std::forward<P>(v)).

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
PValue type accepted by T 's constructor.
参数
vValue to push.

◆ try_emplace()

template<typename T >
template<typename MpmcQueue< T >::Behavior BehaviorT, typename... Args>
bool vlink::MpmcQueue< T >::try_emplace ( Args &&...  args)
inlinenoexcept

Non-blocking in-place construction.

Reads head_, attempts a CAS to claim the slot and retries when the head moves; returns false when the queue is full or notify_to_quit has been observed. On success publishes the slot and, when BehaviorT is kConditionBehavior, notifies a waiter.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
ArgsConstructor argument types forwarded to T.
参数
argsArguments forwarded to T 's constructor.
返回
true on successful enqueue; false on full queue or quit.

◆ try_pop()

template<typename T >
template<typename MpmcQueue< T >::Behavior BehaviorT>
bool vlink::MpmcQueue< T >::try_pop ( T &  v)
inlinenoexcept

Non-blocking pop; returns false when the queue is empty.

Uses CAS retry on tail_; v is untouched on failure.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
参数
vDestination assigned via std::move on success.
返回
true on successful pop; false on empty or quit.

◆ try_push()

template<typename T >
template<typename MpmcQueue< T >::Behavior BehaviorT, typename P >
bool vlink::MpmcQueue< T >::try_push ( P &&  v)
inlinenoexcept

Non-blocking push wrapper around try_emplace.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
PValue type accepted by T 's constructor.
参数
vValue to push.
返回
true on successful enqueue; false on full queue or quit.

该类的文档由以下文件生成: