VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::MpmcQueue< T > 模板类 参考

Fixed-capacity, lock-free, cache-line-aligned MPMC ring buffer. 更多...

#include <mpmc_queue.h>

vlink::MpmcQueue< T > 的协作图:

Public 类型

enum  Behavior : uint8_t { kNoBehavior = 0 , kConditionBehavior = 1 }
 Controls whether condition-variable notifications are sent on push/pop. 更多...

Public 成员函数

 MpmcQueue (size_t capacity) VLINK_NO_INSTRUMENT
 Constructs a MpmcQueue with the given fixed capacity.
 ~MpmcQueue () noexcept VLINK_NO_INSTRUMENT
 Destructor. Destroys any elements still in the queue.
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
 In-place constructs an element without blocking.
template<Behavior BehaviorT = kNoBehavior, typename P>
void push (P &&v) noexcept VLINK_NO_INSTRUMENT
 Pushes a value (by forwarding) and blocks until a slot is available.
template<Behavior BehaviorT = kNoBehavior, typename P>
bool try_push (P &&v) noexcept VLINK_NO_INSTRUMENT
 Pushes a value without blocking; returns false if the queue is full.
template<Behavior BehaviorT = kNoBehavior>
void pop (T &v) noexcept VLINK_NO_INSTRUMENT
 Pops a value by move and blocks until an element is available.
template<Behavior BehaviorT = kNoBehavior>
bool try_pop (T &v) noexcept VLINK_NO_INSTRUMENT
 Pops a value without blocking; returns false if the queue is empty.
size_t capacity () const noexcept VLINK_NO_INSTRUMENT
 Returns the fixed capacity of the queue.
size_t size (bool real=false) const noexcept VLINK_NO_INSTRUMENT
 Returns an approximation of the current number of elements.
bool empty (bool real=false) const noexcept VLINK_NO_INSTRUMENT
 Returns true if the queue appears to be empty.
bool is_full (bool real=false) const noexcept VLINK_NO_INSTRUMENT
 Returns true if the queue appears to be full.
bool wait_not_empty (std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) noexcept VLINK_NO_INSTRUMENT
 Blocks until the queue is not empty (or a timeout elapses).
bool wait_not_full (std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) noexcept VLINK_NO_INSTRUMENT
 Blocks until the queue has space (or a timeout elapses).
void notify_to_quit () noexcept VLINK_NO_INSTRUMENT
 Signals all blocked wait_not_empty() / wait_not_full() callers to exit.

详细描述

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

Fixed-capacity, lock-free, cache-line-aligned MPMC ring buffer.

模板参数
TElement type. Must be moveable.

成员枚举类型说明

◆ Behavior

template<typename T>
enum vlink::MpmcQueue::Behavior : uint8_t

Controls whether condition-variable notifications are sent on push/pop.

Value Behaviour
kNoBehavior No notifications; used with busy-wait or polling
kConditionBehavior Notifies cv_not_empty_ / cv_not_full_ on change
枚举值
kNoBehavior 
kConditionBehavior 

构造及析构函数说明

◆ MpmcQueue()

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

Constructs a MpmcQueue with the given fixed capacity.

Details

参数
capacityMaximum number of elements. Must be >= 1.
异常
std::invalid_argumentif capacity < 1.
std::bad_allocif the internal chunk array cannot be allocated.
函数调用图:
这是这个函数的调用关系图:

◆ ~MpmcQueue()

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

Destructor. Destroys any elements still in the queue.

成员函数说明

◆ capacity()

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

Returns the fixed capacity of the queue.

返回
Capacity as passed to the constructor.
这是这个函数的调用关系图:

◆ 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.

If BehaviorT == kConditionBehavior, notifies wait_not_empty() waiters after push. Silently drops the element if notify_to_quit() has been called.

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

◆ empty()

template<typename T>
bool vlink::MpmcQueue< T >::empty ( bool real = false) const
inlinenodiscardnoexcept

Returns true if the queue appears to be empty.

参数
realIf true, use a more accurate measurement. Default: false.
返回
true if size(real) == 0.
函数调用图:
这是这个函数的调用关系图:

◆ is_full()

template<typename T>
bool vlink::MpmcQueue< T >::is_full ( bool real = false) const
nodiscardnoexcept

Returns true if the queue appears to be full.

参数
realIf true, use a more accurate measurement. Default: false.
返回
true if size(real) >= capacity().
函数调用图:
这是这个函数的调用关系图:

◆ notify_to_quit()

template<typename T>
void vlink::MpmcQueue< T >::notify_to_quit ( )
inlinenoexcept

Signals all blocked wait_not_empty() / wait_not_full() callers to exit.

Sets the quit flag so that all subsequent emplace/push calls are silently dropped and all blocking pop / wait calls return immediately. Used during graceful shutdown.

◆ pop()

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

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

If BehaviorT == kConditionBehavior, notifies wait_not_full() waiters after pop. Returns without modifying v if notify_to_quit() has been called.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
参数
vOutput: receives the popped element via move.
函数调用图:

◆ push()

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

Pushes a value (by forwarding) and blocks until a slot is available.

Forwards to emplace<BehaviorT>(std::forward<P>(v)).

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
PValue type (lvalue or rvalue reference).
参数
vValue to push.
函数调用图:

◆ size()

template<typename T>
size_t vlink::MpmcQueue< T >::size ( bool real = false) const
inlinenodiscardnoexcept

Returns an approximation of the current number of elements.

If real is false (default), returns head - tail (fast but may be slightly stale). If real is true, retries up to 50 times until a stable snapshot is obtained.

参数
realIf true, use a more accurate but slower measurement. Default: false.
返回
Approximate element count.
函数调用图:
这是这个函数的调用关系图:

◆ try_emplace()

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

In-place constructs an element without blocking.

Returns false immediately if the queue is full.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
ArgsConstructor argument types.
参数
argsArguments forwarded to T's constructor.
返回
true if the element was enqueued; false if the queue was full.
这是这个函数的调用关系图:

◆ try_pop()

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

Pops a value without blocking; returns false if the queue is empty.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
参数
vOutput: receives the popped element via move.
返回
true if an element was popped; false if empty.

◆ try_push()

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

Pushes a value without blocking; returns false if the queue is full.

模板参数
BehaviorTNotification behaviour. Default: kNoBehavior.
PValue type.
参数
vValue to push.
返回
true if pushed; false if full.
函数调用图:

◆ wait_not_empty()

template<typename T>
bool vlink::MpmcQueue< T >::wait_not_empty ( std::chrono::milliseconds timeout = std::chrono::milliseconds(0))
inlinenoexcept

Blocks until the queue is not empty (or a timeout elapses).

If timeout is std::chrono::milliseconds(0), blocks indefinitely. Returns immediately if the queue already has elements. Returns false if notify_to_quit() was called.

参数
timeoutWait duration. 0 = wait indefinitely. Default: 0.
返回
true if the queue became non-empty; false on quit.
函数调用图:

◆ wait_not_full()

template<typename T>
bool vlink::MpmcQueue< T >::wait_not_full ( std::chrono::milliseconds timeout = std::chrono::milliseconds(0))
inlinenoexcept

Blocks until the queue has space (or a timeout elapses).

If timeout is std::chrono::milliseconds(0), blocks indefinitely. Returns immediately if the queue is not full. Returns false if notify_to_quit() was called.

参数
timeoutWait duration. 0 = wait indefinitely. Default: 0.
返回
true if space is available; false on quit.
函数调用图:
这是这个函数的调用关系图:

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