|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
有界 MPMC 字节队列内核 / Bounded MPMC byte-queue core More...
#include <mpmc_queue_base.hpp>
Public Types | |
| using | SequenceType |
| 单调递增的逻辑序号类型 / Monotonic logical sequence type. | |
| using | SequenceDiffType |
Public Member Functions | |
| MPMCQueueBase (size_t element_size, size_t capacity) | |
| 构造一个字节队列内核 / Construct one byte-queue core | |
| ~MPMCQueueBase () | |
| 析构字节队列内核 / Destroy the byte-queue core | |
| ErrorCode | PushBytes (const void *value) |
| 按字节入队一个 payload / Enqueue one payload by bytes | |
| ErrorCode | PopBytes (void *value=nullptr) |
| 按字节出队一个 payload;传空指针时只丢弃队头元素 / Dequeue one payload by bytes; pass null to discard the front item only | |
| size_t | MaxSize () const |
| 获取队列最大容量 / Get the maximum queue capacity | |
| size_t | Size () const |
| 获取并发快照下的当前元素数 / Get the current approximate element count | |
| size_t | EmptySize () const |
| 获取剩余空槽数 / Get the current free-slot count | |
| size_t | ElementSize () const |
| 获取单个 payload 的字节数 / Get the byte size of one payload | |
有界 MPMC 字节队列内核 / Bounded MPMC byte-queue core
这个内核把并发协议和字节搬运集中在一个非模板实现里,以减少不同 payload 类型各自实例化一整套无锁协议所带来的 flash 膨胀。它只负责搬运固定大小、 默认字宽对齐的字节 payload;类型语义由上层薄包装负责。
This core keeps the concurrency protocol and byte-copying logic in one non-template implementation so different payload types do not each instantiate a full copy of the lock-free protocol. It only moves fixed-size, word-aligned byte payloads; type semantics are handled by thin wrappers above it.
Definition at line 28 of file mpmc_queue_base.hpp.
序号差值判定类型 / Signed type used for sequence-delta checks.
Definition at line 33 of file mpmc_queue_base.hpp.
单调递增的逻辑序号类型 / Monotonic logical sequence type.
Definition at line 31 of file mpmc_queue_base.hpp.
| LibXR::MPMCQueueBase::MPMCQueueBase | ( | size_t | element_size, |
| size_t | capacity ) |
构造一个字节队列内核 / Construct one byte-queue core
构造字节队列内核 / Construct the byte-queue core
| element_size | 单个 payload 的字节数 / Byte size of one payload |
| capacity | 队列容量 / Queue capacity |
Definition at line 15 of file mpmc_queue_base.cpp.
| LibXR::MPMCQueueBase::~MPMCQueueBase | ( | ) |
析构字节队列内核 / Destroy the byte-queue core
Definition at line 44 of file mpmc_queue_base.cpp.
|
inlinenodiscard |
获取单个 payload 的字节数 / Get the byte size of one payload
Definition at line 96 of file mpmc_queue_base.hpp.
|
inlinenodiscard |
获取剩余空槽数 / Get the current free-slot count
Definition at line 91 of file mpmc_queue_base.hpp.
|
inlinenodiscard |
获取队列最大容量 / Get the maximum queue capacity
Definition at line 72 of file mpmc_queue_base.hpp.
| ErrorCode LibXR::MPMCQueueBase::PopBytes | ( | void * | value = nullptr | ) |
按字节出队一个 payload;传空指针时只丢弃队头元素 / Dequeue one payload by bytes; pass null to discard the front item only
按字节出队一个 payload / Dequeue one payload by bytes
| value | 用于接收 payload 的缓冲区;传 nullptr 时仅丢弃 / Buffer that receives the payload; pass nullptr to discard only |
ErrorCode::OK;队列空返回 ErrorCode::EMPTY Returns ErrorCode::OK on success; returns ErrorCode::EMPTY when the queue is empty| value | 用于接收 payload 的缓冲区;传 nullptr 时仅丢弃队头元素 / Buffer that receives the payload; pass nullptr to discard the front element only |
Definition at line 96 of file mpmc_queue_base.cpp.
| ErrorCode LibXR::MPMCQueueBase::PushBytes | ( | const void * | value | ) |
按字节入队一个 payload / Enqueue one payload by bytes
| value | 指向待入队 payload 的指针 / Pointer to the payload to enqueue |
ErrorCode::OK;队列满返回 ErrorCode::FULL;空指针返回 ErrorCode::PTR_NULL Returns ErrorCode::OK on success; ErrorCode::FULL when the queue is full; ErrorCode::PTR_NULL when value is null| value | 指向待入队 payload 的指针 / Pointer to the payload to enqueue |
Definition at line 54 of file mpmc_queue_base.cpp.
|
nodiscard |
获取并发快照下的当前元素数 / Get the current approximate element count
SequenceType 的模差值估算已用槽数,再钳到 [0, MaxSize()], 因此即使极端长寿命下序号回绕后,它仍然只是近似值,而不是精确值。 This value is an approximate snapshot:SequenceType differences and then clamped to [0, MaxSize()], so it remains approximate rather than exact even after very long-lived sequence wraparound.[0, MaxSize()] Approximate element count from a concurrent snapshot, clamped to [0, MaxSize()] Definition at line 139 of file mpmc_queue_base.cpp.