|
VLink 2.0.0
A high-performance communication middleware
|
Fixed-capacity, lock-free, cache-line-aligned MPMC ring buffer. 更多...
#include <mpmc_queue.h>
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. | |
Fixed-capacity, lock-free, cache-line-aligned MPMC ring buffer.
| T | Element type. Must be moveable. |
| enum vlink::MpmcQueue::Behavior : uint8_t |
|
inlineexplicit |
|
inlinenoexcept |
Destructor. Destroys any elements still in the queue.
|
inlinenodiscardnoexcept |
Returns the fixed capacity of the queue.
|
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.
| BehaviorT | Notification behaviour. Default: kNoBehavior. |
| Args | Constructor argument types. |
| args | Arguments forwarded to T's constructor. |
|
inlinenodiscardnoexcept |
Returns true if the queue appears to be empty.
| real | If true, use a more accurate measurement. Default: false. |
true if size(real) == 0.
|
nodiscardnoexcept |
Returns true if the queue appears to be full.
| real | If true, use a more accurate measurement. Default: false. |
true if size(real) >= capacity().
|
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.
|
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.
| BehaviorT | Notification behaviour. Default: kNoBehavior. |
| v | Output: receives the popped element via move. |
|
inlinenoexcept |
Pushes a value (by forwarding) and blocks until a slot is available.
Forwards to emplace<BehaviorT>(std::forward<P>(v)).
| BehaviorT | Notification behaviour. Default: kNoBehavior. |
| P | Value type (lvalue or rvalue reference). |
| v | Value to push. |
|
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.
| real | If true, use a more accurate but slower measurement. Default: false. |
|
inlinenodiscardnoexcept |
In-place constructs an element without blocking.
Returns false immediately if the queue is full.
| BehaviorT | Notification behaviour. Default: kNoBehavior. |
| Args | Constructor argument types. |
| args | Arguments forwarded to T's constructor. |
true if the element was enqueued; false if the queue was full.
|
inlinenodiscardnoexcept |
Pops a value without blocking; returns false if the queue is empty.
| BehaviorT | Notification behaviour. Default: kNoBehavior. |
| v | Output: receives the popped element via move. |
true if an element was popped; false if empty.
|
inlinenodiscardnoexcept |
Pushes a value without blocking; returns false if the queue is full.
| BehaviorT | Notification behaviour. Default: kNoBehavior. |
| P | Value type. |
| v | Value to push. |
true if pushed; false if full.
|
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.
| timeout | Wait duration. 0 = wait indefinitely. Default: 0. |
true if the queue became non-empty; false on quit.
|
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.
| timeout | Wait duration. 0 = wait indefinitely. Default: 0. |
true if space is available; false on quit.