面向任务与中断的小容量消息槽池。 Small message slot pool shared between tasks and interrupts.
More...
|
| | SlotPool (size_t slot_count) |
| | 构造槽池 / Construct one slot pool.
|
| |
| T & | At (size_t index) |
| | 访问自己持有的槽(写入中或读取中)/ Access an owned slot (writing or reading).
|
| |
| const T & | At (size_t index) const |
| | 只读访问自己持有的槽 / Read-only access to an owned slot.
|
| |
| ErrorCode | Put (const T &value) |
| | 便捷入队:Acquire + 拷贝 + Publish / Convenient enqueue: Acquire + copy + Publish.
|
| |
| ErrorCode | Get (T &value) |
| | 便捷出队:Take + 拷贝 + Release / Convenient dequeue: Take + copy + Release.
|
| |
| | SlotPoolBase (size_t slot_size, size_t slot_align, size_t slot_count) |
| | 构造槽池内核 / Construct the slot-pool core.
|
| |
| | ~SlotPoolBase () |
| | 析构槽池内核 / Destroy the slot-pool core.
|
| |
| ErrorCode | Acquire (size_t &index) |
| | 认领一个空闲槽(空闲 → 写入中) / Claim one free slot (free -> writing).
|
| |
| void | Publish (size_t index) |
| | 发布已写好的槽(写入中 → 就绪),并取得发布序号 / Publish a fully written slot (writing -> ready) and take a publish sequence number.
|
| |
| ErrorCode | Take (size_t &index) |
| | 认领序号最小的就绪槽(就绪 → 读取中) / Claim the oldest ready slot (ready -> reading).
|
| |
| void | Release (size_t index) |
| | 释放自己持有的槽(写入中或读取中 → 空闲) / Release an owned slot (writing or reading -> free).
|
| |
| size_t | Size () const |
| | 获取槽总数 / Get the total number of slots.
|
| |
|
| enum | SlotState : uint32_t { SLOT_FREE = 0
, SLOT_WRITING = 1
, SLOT_READY = 2
, SLOT_READING = 3
} |
| | 槽状态 / Slot state. More...
|
| |
| void * | SlotPtr (size_t index) |
| | 获取指定槽位的存储地址 / Get the storage address of one slot.
|
| |
| const void * | SlotPtr (size_t index) const |
| | 获取指定槽位的存储地址(只读)/ Get the storage address of one slot (const).
|
| |
| const size_t | slot_size_ |
| | 单个槽的字节数 / Byte size of one slot.
|
| |
| const size_t | slot_count_ |
| | 槽总数 / Total number of slots.
|
| |
| const size_t | slot_stride_ |
| | 相邻槽位之间的步长 / Byte stride between slots.
|
| |
| const size_t | alloc_align_ |
| |
| std::atomic< uint32_t > * | states_ |
| | 每槽状态字 / Per-slot atomic state word.
|
| |
| std::atomic< uint32_t > * | seqs_ |
| | 每槽发布序号 / Per-slot publish sequence.
|
| |
| std::byte * | slots_ |
| | 槽存储缓冲区 / Byte buffer storing slots.
|
| |
| std::atomic< uint32_t > | publish_seq_ |
| |
| std::atomic< uint32_t > | release_count_ |
| |
| static constexpr size_t | INVALID_INDEX = static_cast<size_t>(-1) |
| | 无效槽位下标 / Sentinel for "no slot chosen".
|
| |
template<typename T>
class LibXR::SlotPool< T >
面向任务与中断的小容量消息槽池。 Small message slot pool shared between tasks and interrupts.
每个槽一个原子状态(空闲、写入中、就绪、读取中),所有状态转换用 CAS 完成;Publish 时取全局递增的发布序号,Take 选序号最小的就绪槽。 适用于几到几十个槽的小容量场合,Acquire/Take 是 O(N) 扫描。 一个被打断的操作只占住它自己的槽:任务停在 Acquire、写入、Publish、 Take、读取、Release 的任何中间点时,中断里的 Put/Get 都不会被挡住, 拿到的 FULL/EMPTY 反映那一刻的真实状态。多生产者多消费者均可用;请勿在 NMI 中使用。出队顺序按发布序号,同一发布者内部保序;不保证跨发布者的 全局先进先出。
Each slot carries one atomic state (free, writing, ready, reading) and every state transition is a CAS; Publish takes a globally increasing sequence and Take picks the ready slot with the smallest sequence. It targets small pools of a few to a few dozen slots; Acquire/Take are O(N) scans. An interrupted operation only occupies its own slot: while a task stops at any intermediate point of Acquire, writing, Publish, Take, reading or Release, a Put/Get from an interrupt is never blocked by it, and the FULL/EMPTY it observes reflects the true state at that moment. Any number of producers and consumers may run concurrently; do not use it inside NMI. Dequeue order follows the publish sequence, order inside one publisher is preserved, and no global cross-publisher FIFO is guaranteed.
- Template Parameters
-
| T | 槽存储的数据类型 / Slot element type. |
Definition at line 195 of file slot_pool.hpp.