|
libxr
1.0
Want to be the best embedded framework
|
单生产者单消费者字节队列内核 / Single-producer single-consumer byte-queue core More...
#include <spsc_queue_base.hpp>
Public Types | |
| using | IndexType = size_t |
| 环形缓冲区索引类型 / Ring-buffer index type. | |
Public Member Functions | |
| SPSCQueueBase (size_t element_size, size_t capacity) | |
| 构造 SPSC 字节队列内核 / Construct the SPSC byte-queue core | |
| SPSCQueueBase (size_t element_size, size_t element_align, size_t capacity) | |
| 构造 SPSC 字节队列内核并指定元素对齐 / Construct the SPSC byte-queue core with explicit element alignment | |
| ~SPSCQueueBase () | |
| 析构 SPSC 字节队列内核 / Destroy the SPSC 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 | |
| ErrorCode | PeekBytes (void *value) |
| 按字节查看一个队头 payload 但不出队 / Peek one front payload by bytes without dequeuing it | |
| ErrorCode | PushBatchBytes (const void *data, size_t count) |
| 按字节批量入队多个 payload / Enqueue multiple payloads by bytes | |
| template<typename Writer > | |
| ErrorCode | PushBytesWithWriter (size_t count, Writer &&writer) |
| 通过写入器回调批量入队 payload / Enqueue payloads through a writer callback | |
| ErrorCode | PopBatchBytes (void *data, size_t count) |
| 按字节批量出队多个 payload / Dequeue multiple payloads by bytes | |
| template<typename Reader > | |
| ErrorCode | PopBytesWithReader (size_t count, Reader &&reader) |
| 通过读取器回调批量出队 payload / Dequeue payloads through a reader callback | |
| ErrorCode | PeekBatchBytes (void *data, size_t count) |
| 按字节批量查看多个 payload 但不出队 / Peek multiple payloads by bytes without dequeuing them | |
| void | Reset () |
| 重置队列状态 / Reset the queue state | |
| size_t | Size () const |
| 获取当前已用元素数 / Get the current element count | |
| size_t | EmptySize () const |
| 获取剩余空槽数 / Get the current free-slot count | |
| size_t | MaxSize () const |
| 获取队列最大容量 / Get the maximum queue capacity | |
Private Member Functions | |
| void | InitStorage () |
| std::byte * | PayloadPtr (IndexType index) |
| 获取指定槽位 payload 起始地址 / Get the payload base address of one slot | |
| const std::byte * | PayloadPtr (IndexType index) const |
| 获取指定槽位 payload 起始地址(只读) / Get the payload base address of one slot (const) | |
| size_t | RingCapacity () const |
| 获取环形缓冲区的物理槽位总数 / Get the physical ring-slot count | |
| IndexType | Increment (IndexType index) const |
| 沿环形缓冲区推进一个槽位 / Advance one slot along the ring | |
| SPSCQueueBase (const SPSCQueueBase &) | |
| 禁止拷贝构造。 Non-copyable. | |
| SPSCQueueBase & | operator= (const SPSCQueueBase &) |
| 禁止拷贝赋值。 Non-copy-assignable. | |
| SPSCQueueBase (SPSCQueueBase &&) | |
| 禁止移动构造。 Non-movable. | |
| SPSCQueueBase & | operator= (SPSCQueueBase &&) |
| 禁止移动赋值。 Non-move-assignable. | |
Static Private Member Functions | |
| static size_t | AlignUpChecked (size_t size, size_t align) |
| 安全地向上对齐字节数 / Safely align one byte count upward | |
| static size_t | ComputeStride (size_t element_size, size_t element_align) |
| static size_t | MultiplyChecked (size_t lhs, size_t rhs) |
| 安全地计算两个字节数的乘积 / Safely multiply two byte counts | |
Private Attributes | |
| const size_t | element_size_ |
| 单个 payload 的字节数。 Byte size of one payload. | |
| const size_t | capacity_ |
| 队列容量。 Queue capacity. | |
| const size_t | payload_alloc_align_ |
| 整体分配对齐。 Allocation alignment for the payload buffer. | |
| const size_t | payload_stride_ |
| 相邻 payload 槽位之间的步长。 Byte stride between adjacent payload slots. | |
| std::byte * | payloads_ |
| payload 字节缓冲区。 Byte buffer storing payloads. | |
| std::atomic< IndexType > | head_ |
| 下一个待出队的环形下标。 Next ring index to dequeue. | |
| std::atomic< IndexType > | tail_ |
| 下一个待入队的环形下标。 Next ring index to enqueue. | |
单生产者单消费者字节队列内核 / Single-producer single-consumer byte-queue core
这个内核只负责 SPSC ring 的索引推进、容量判断与原始字节存储,不包含多消费者 抢占逻辑,也不暴露任何 CAS 路径。上层 SPSCQueue<Data> 只负责把具体类型 Data 映射到这些字节槽位。
This core contains only the SPSC ring progression, capacity checks, and raw byte storage. It does not include any multi-consumer claiming logic or expose any CAS-based path. The upper SPSCQueue<Data> wrapper is responsible only for mapping the concrete Data type onto these byte slots.
Definition at line 27 of file spsc_queue_base.hpp.
| using LibXR::SPSCQueueBase::IndexType = size_t |
环形缓冲区索引类型 / Ring-buffer index type.
Definition at line 30 of file spsc_queue_base.hpp.
|
inline |
构造 SPSC 字节队列内核 / Construct the SPSC byte-queue core
| element_size | 单个 payload 的字节数 / Byte size of one payload |
| capacity | 队列容量 / Queue capacity |
Definition at line 37 of file spsc_queue_base.hpp.
|
inline |
构造 SPSC 字节队列内核并指定元素对齐 / Construct the SPSC byte-queue core with explicit element alignment
| element_size | 单个 payload 的字节数 / Byte size of one payload |
| element_align | 单个 payload 的对齐要求 / Alignment requirement of one payload |
| capacity | 队列容量 / Queue capacity |
Definition at line 56 of file spsc_queue_base.hpp.
|
inline |
析构 SPSC 字节队列内核 / Destroy the SPSC byte-queue core
Definition at line 87 of file spsc_queue_base.hpp.
|
inlinestaticprivate |
安全地向上对齐字节数 / Safely align one byte count upward
| size | 待对齐字节数 / Byte count to align |
| align | 目标对齐粒度 / Target alignment granularity |
Definition at line 497 of file spsc_queue_base.hpp.
|
inlinestaticprivate |
Definition at line 505 of file spsc_queue_base.hpp.
|
inline |
获取剩余空槽数 / Get the current free-slot count
Definition at line 434 of file spsc_queue_base.hpp.
沿环形缓冲区推进一个槽位 / Advance one slot along the ring
| index | 当前槽位下标 / Current slot index |
Definition at line 477 of file spsc_queue_base.hpp.
|
inlineprivate |
Definition at line 69 of file spsc_queue_base.hpp.
|
inline |
获取队列最大容量 / Get the maximum queue capacity
Definition at line 440 of file spsc_queue_base.hpp.
|
inlinestaticprivate |
安全地计算两个字节数的乘积 / Safely multiply two byte counts
| lhs | 左操作数 / Left operand |
| rhs | 右操作数 / Right operand |
Definition at line 519 of file spsc_queue_base.hpp.
|
inlineprivate |
获取指定槽位 payload 起始地址 / Get the payload base address of one slot
| index | 目标槽位下标 / Target slot index |
Definition at line 448 of file spsc_queue_base.hpp.
|
inlineprivate |
获取指定槽位 payload 起始地址(只读) / Get the payload base address of one slot (const)
| index | 目标槽位下标 / Target slot index |
Definition at line 460 of file spsc_queue_base.hpp.
|
inline |
按字节批量查看多个 payload 但不出队 / Peek multiple payloads by bytes without dequeuing them
| data | 用于接收 payload 的字节缓冲区 / Byte buffer receiving payloads |
| count | payload 个数 / Number of payloads |
ErrorCode::OK;元素不足返回 ErrorCode::EMPTY Returns ErrorCode::OK on success; returns ErrorCode::EMPTY when there are not enough payloads available Definition at line 376 of file spsc_queue_base.hpp.
|
inline |
按字节查看一个队头 payload 但不出队 / Peek one front payload by bytes without dequeuing it
| value | 用于接收 payload 的缓冲区 / Buffer that receives the payload |
ErrorCode::OK;队列空返回 ErrorCode::EMPTY;空指针返回 ErrorCode::PTR_NULL Returns ErrorCode::OK on success; returns ErrorCode::EMPTY when the queue is empty; returns ErrorCode::PTR_NULL when value is null Definition at line 155 of file spsc_queue_base.hpp.
|
inline |
按字节批量出队多个 payload / Dequeue multiple payloads by bytes
| data | 用于接收 payload 的字节缓冲区;传 nullptr 时仅丢弃 / Byte buffer receiving payloads; pass nullptr to discard only |
| count | payload 个数 / Number of payloads |
ErrorCode::OK;元素不足返回 ErrorCode::EMPTY Returns ErrorCode::OK on success; returns ErrorCode::EMPTY when there are not enough payloads available Definition at line 278 of file spsc_queue_base.hpp.
|
inline |
按字节出队一个 payload;传空指针时仅丢弃队头元素 / Dequeue one payload by bytes; pass null to discard the front item only
| 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 Definition at line 129 of file spsc_queue_base.hpp.
|
inline |
通过读取器回调批量出队 payload / Dequeue payloads through a reader callback
| Reader | 读取器类型 / Reader callback type |
| count | payload 个数 / Number of payloads |
| reader | 读取器,签名为 ErrorCode(const void* buffer, size_t chunk_count) / Reader with signature ErrorCode(const void* buffer, size_t chunk_count) |
ErrorCode::OK;元素不足返回 ErrorCode::EMPTY;否则返回读取器错误码 / Returns ErrorCode::OK on success, ErrorCode::EMPTY when there are not enough payloads, otherwise returns the reader error code chunk_count * element_size / The reader receives one contiguous payload storage chunk each time, with byte length chunk_count * element_size Definition at line 327 of file spsc_queue_base.hpp.
|
inline |
按字节批量入队多个 payload / Enqueue multiple payloads by bytes
| data | 指向 payload 数组的字节指针 / Byte pointer to the payload array |
| count | payload 个数 / Number of payloads |
ErrorCode::OK;队列满返回 ErrorCode::FULL Returns ErrorCode::OK on success; returns ErrorCode::FULL when the queue is full Definition at line 180 of file spsc_queue_base.hpp.
|
inline |
按字节入队一个 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; returns ErrorCode::FULL when the queue is full; returns ErrorCode::PTR_NULL when value is null Definition at line 100 of file spsc_queue_base.hpp.
|
inline |
通过写入器回调批量入队 payload / Enqueue payloads through a writer callback
| Writer | 写入器类型 / Writer callback type |
| count | payload 个数 / Number of payloads |
| writer | 写入器,签名为 ErrorCode(void* buffer, size_t chunk_count) / Writer with signature ErrorCode(void* buffer, size_t chunk_count) |
ErrorCode::OK;空间不足返回 ErrorCode::FULL;否则返回写入器错误码 / Returns ErrorCode::OK on success, ErrorCode::FULL when free space is insufficient, otherwise returns the writer error code chunk_count * element_size / The writer receives one contiguous payload storage chunk each time, with byte length chunk_count * element_size Definition at line 229 of file spsc_queue_base.hpp.
|
inline |
重置队列状态 / Reset the queue state
Definition at line 412 of file spsc_queue_base.hpp.
|
inlineprivate |
获取环形缓冲区的物理槽位总数 / Get the physical ring-slot count
Definition at line 470 of file spsc_queue_base.hpp.
|
inline |
获取当前已用元素数 / Get the current element count
Definition at line 422 of file spsc_queue_base.hpp.
|
private |
队列容量。 Queue capacity.
Definition at line 531 of file spsc_queue_base.hpp.
|
private |
单个 payload 的字节数。 Byte size of one payload.
Definition at line 530 of file spsc_queue_base.hpp.
|
private |
下一个待出队的环形下标。 Next ring index to dequeue.
Definition at line 537 of file spsc_queue_base.hpp.
|
private |
整体分配对齐。 Allocation alignment for the payload buffer.
Definition at line 532 of file spsc_queue_base.hpp.
|
private |
相邻 payload 槽位之间的步长。 Byte stride between adjacent payload slots.
Definition at line 533 of file spsc_queue_base.hpp.
|
private |
payload 字节缓冲区。 Byte buffer storing payloads.
Definition at line 534 of file spsc_queue_base.hpp.
|
private |
下一个待入队的环形下标。 Next ring index to enqueue.
Definition at line 539 of file spsc_queue_base.hpp.