|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
单生产者单消费者字节队列内核 / 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 | |
| template<typename Writer > | |
| size_t | ProduceWithWriter (size_t limit, Writer &&writer) |
| 通过一次双 span 回调生产 payload 前缀 / Produce a payload prefix through one two-span 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 | |
| template<typename Reader > | |
| size_t | ConsumeWithReader (size_t limit, Reader &&reader) |
| 通过一次双 span 回调消费 payload 前缀 / Consume a payload prefix through one two-span reader callback. | |
| ErrorCode | PeekBatchBytes (void *data, size_t count) |
| 按字节批量查看多个 payload 但不出队 / Peek multiple payloads by bytes without dequeuing them | |
| void | Reset () |
| 从 consumer 侧丢弃当前可见的全部 payload / Discard all currently available payloads from the consumer side | |
| 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 | |
单生产者单消费者字节队列内核 / 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 88 of file spsc_queue_base.hpp.
|
inline |
通过一次双 span 回调消费 payload 前缀 / Consume a payload prefix through one two-span reader callback.
| Reader | 读取器类型 / Reader callback type. |
| limit | 最多提供的 payload 个数 / Maximum number of offered payloads. |
| reader | 接收两段数据和元素数,返回已接受的前缀个数 / Receives two data pointers and element counts; returns the accepted prefix count. |
Definition at line 438 of file spsc_queue_base.hpp.
|
inline |
获取剩余空槽数 / Get the current free-slot count
Definition at line 549 of file spsc_queue_base.hpp.
|
inline |
获取队列最大容量 / Get the maximum queue capacity
Definition at line 555 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; count 不为 0 且 data 为空时返回 ErrorCode::PTR_NULL Returns ErrorCode::OK on success; returns ErrorCode::EMPTY when there are not enough payloads available; returns ErrorCode::PTR_NULL when data is null and count is not 0 Definition at line 481 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 157 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 331 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 130 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 382 of file spsc_queue_base.hpp.
|
inline |
通过一次双 span 回调生产 payload 前缀 / Produce a payload prefix through one two-span writer callback.
| Writer | 写入器类型 / Writer callback type. |
| limit | 最多提供的 payload 个数 / Maximum number of offered payloads. |
| writer | 接收两段存储和元素数,返回已写入的前缀个数 / Receives two storage pointers and element counts; returns the written prefix count. |
nullptr,所有指针只在回调期间 有效 / The callback is skipped when the offered count is zero; an empty second span is nullptr, and all pointers are valid only during the callback. Definition at line 290 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; count 不为 0 且 data 为空时返回 ErrorCode::PTR_NULL Returns ErrorCode::OK on success; returns ErrorCode::FULL when the queue is full; returns ErrorCode::PTR_NULL when data is null and count is not 0 Definition at line 184 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 101 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 234 of file spsc_queue_base.hpp.
|
inline |
从 consumer 侧丢弃当前可见的全部 payload / Discard all currently available payloads from the consumer side
本方法读取 producer 已发布的 tail 快照,并将 consumer head 推进到该位置;不会 写入 tail,因此单个 producer 可以继续运行。与该快照并发发布的 payload 可能被 丢弃,也可能保留。
This method snapshots the producer-published tail and advances the consumer head to it. It never writes tail, so the single producer may continue. Payloads published concurrently with the snapshot may be discarded or retained.
Definition at line 526 of file spsc_queue_base.hpp.
|
inline |
获取当前已用元素数 / Get the current element count
Definition at line 536 of file spsc_queue_base.hpp.