|
VLink
2.0.0
A high-performance communication middleware
|
Non-template base class that owns every element-type-independent piece of state. 更多...
#include <mpmc_queue.h>
类 | |
| struct | QuitFlag |
Public 类型 | |
| enum | Behavior : uint8_t { kNoBehavior = 0 , kConditionBehavior = 1 } |
| Per-call notification behaviour selector. 更多... | |
Public 成员函数 | |
| size_t | capacity () const noexcept VLINK_NO_INSTRUMENT |
| Returns the fixed capacity chosen at construction. 更多... | |
| size_t | size (bool real=false) const noexcept VLINK_NO_INSTRUMENT |
| Returns an approximate count of currently enqueued elements. 更多... | |
| bool | empty (bool real=false) const noexcept VLINK_NO_INSTRUMENT |
Returns true when the queue appears empty. 更多... | |
| bool | is_full (bool real=false) const noexcept VLINK_NO_INSTRUMENT |
Returns true when the queue appears full. 更多... | |
| bool | wait_not_empty (std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) noexcept VLINK_NO_INSTRUMENT |
Blocks until the queue is non-empty or timeout elapses. 更多... | |
| bool | wait_not_full (std::chrono::milliseconds timeout=std::chrono::milliseconds(0)) noexcept VLINK_NO_INSTRUMENT |
Blocks until the queue has free space or timeout elapses. 更多... | |
| void | notify_to_quit () noexcept VLINK_NO_INSTRUMENT |
| Signals graceful shutdown to every waiter and rejects further pushes. 更多... | |
Protected 成员函数 | |
| MpmcQueueBase (size_t capacity) | |
| ~MpmcQueueBase () noexcept=default | |
| constexpr size_t | idx (size_t i) const noexcept |
| constexpr size_t | turn (size_t i) const noexcept |
静态 Protected 成员函数 | |
| static void | throw_mpmc_invalid_capacity () |
| static void | throw_mpmc_alignment_failure () |
Protected 属性 | |
| std::atomic< size_t > | head_ {0U} |
| void * | chunk_storage_ {nullptr} |
| size_t | capacity_ {0} |
| std::mutex | cv_mtx_ |
| std::atomic< size_t > | tail_ {0U} |
| ConditionVariable | cv_not_empty_ |
| ConditionVariable | cv_not_full_ |
| struct vlink::MpmcQueueBase::QuitFlag | quit_flag_ |
静态 Protected 属性 | |
| static constexpr std::memory_order | kMemoryOrderAcquire = std::memory_order_acquire |
| static constexpr std::memory_order | kMemoryOrderRelease = std::memory_order_release |
| static constexpr std::memory_order | kMemoryOrderRelaxed = std::memory_order_relaxed |
| static constexpr size_t | kInterferenceSize = 64U |
| static constexpr size_t | kFirstSpinTimes = 32U |
Non-template base class that owns every element-type-independent piece of state.
Hosts the cache-line aligned head_ / tail_ cursors, the optional condition variables, the quit flag, the shared capacity and the void* slot for the Chunk array storage. The element type T – including the Chunk struct and the move / destroy plumbing – lives in MpmcQueue<T>, which accesses slots via a typed cast of chunk_storage_.
| enum vlink::MpmcQueueBase::Behavior : uint8_t |
Per-call notification behaviour selector.
Selected via the BehaviorT template argument to emplace / push / pop and the try_* variants. Use kConditionBehavior whenever consumers or producers may block on wait_not_empty / wait_not_full; otherwise the cv notifications are pure overhead.
| 枚举值 | |
|---|---|
| kNoBehavior | |
| kConditionBehavior | |
|
explicitprotected |
|
protecteddefaultnoexcept |
|
noexcept |
Returns the fixed capacity chosen at construction.
>= 1).
|
noexcept |
Returns true when the queue appears empty.
| real | Pass true to use the retrying size variant. |
true when no elements are currently enqueued (approximately).
|
inlineconstexprprotectednoexcept |
|
noexcept |
Returns true when the queue appears full.
| real | Pass true to use the retrying size variant. |
true when the queue is at or above capacity.
|
noexcept |
Signals graceful shutdown to every waiter and rejects further pushes.
Sets the internal quit flag with release ordering and broadcasts both condition variables. Existing wait_not_empty / wait_not_full calls return false; subsequent emplace / push silently drop their payload; try_pop returns false without touching the output. Safe to call multiple times.
|
noexcept |
Returns an approximate count of currently enqueued elements.
Computes head_ - tail_ using acquire loads of both cursors; concurrent updates may produce a slightly stale value. real == true retries up to 50 times until the tail_ reading is stable, at the cost of latency. The result is clamped at 0 to suppress transient head_ < tail_ wrap-arounds.
| real | When true, retries for a stable snapshot. Default: false. |
|
staticprotected |
|
staticprotected |
|
inlineconstexprprotectednoexcept |
|
noexcept |
Blocks until the queue is non-empty or timeout elapses.
Fast path: returns immediately when empty(true) is false. Slow path: waits on cv_not_empty until a producer publishes under kConditionBehavior or notify_to_quit fires.
| timeout | Maximum wait; 0 means wait forever. Default: 0. |
true when the queue became non-empty; false on timeout or quit.
|
noexcept |
Blocks until the queue has free space or timeout elapses.
Mirror of wait_not_empty for producers; waits on cv_not_full.
| timeout | Maximum wait; 0 means wait forever. Default: 0. |
true when space became available; false on timeout or quit.
|
protected |
|
protected |
|
mutableprotected |
|
protected |
|
protected |
|
protected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
protected |
|
protected |