11#include "libxr_def.hpp"
33 std::make_signed_t<SequenceType>;
84 [[nodiscard]]
size_t Size()
const;
106 [[nodiscard]]
const void*
PayloadPtr(
size_t index)
const;
108 [[nodiscard]]
static size_t AlignUpChecked(
size_t value,
size_t align);
115 std::max(
alignof(
size_t),
alignof(std::max_align_t));
有界 MPMC 字节队列内核 / Bounded MPMC byte-queue core
size_t SequenceType
单调递增的逻辑序号类型 / Monotonic logical sequence type.
MPMCQueueBase(size_t element_size, size_t capacity)
构造一个字节队列内核 / Construct one byte-queue core
size_t EmptySize() const
获取剩余空槽数 / Get the current free-slot count
static size_t MultiplyChecked(size_t lhs, size_t rhs)
安全地计算乘积。 Safely multiply two size values.
std::make_signed_t< SequenceType > SequenceDiffType
序号差值判定类型 / Signed type used for sequence-delta checks.
static size_t AlignUpChecked(size_t value, size_t align)
安全地向上对齐字节数。 Safely align one byte count upward.
size_t Size() const
获取并发快照下的当前元素数 / Get the current approximate element count
std::byte * payloads_
payload 字节缓冲区。 Byte buffer storing payloads.
const size_t payload_stride_
相邻 payload 槽位之间的步长。 Byte stride between adjacent payload slots.
std::atomic< SequenceType > head_
下一个待出队的逻辑位置。 Next logical dequeue position.
const size_t capacity_
队列容量。 Queue capacity.
ErrorCode PopBytes(void *value=nullptr)
按字节出队一个 payload;传空指针时只丢弃队头元素 / Dequeue one payload by bytes; pass null to discard the front item only
static constexpr size_t PAYLOAD_ALLOC_ALIGN
payload 缓冲区整体分配对齐 / Allocation alignment used for the whole payload buffer
MPMCQueueBase(MPMCQueueBase &&)
禁止移动构造。 Non-movable.
size_t ElementSize() const
获取单个 payload 的字节数 / Get the byte size of one payload
void * PayloadPtr(size_t index)
获取指定槽位 payload 起始地址。 Get the payload base address of one slot.
~MPMCQueueBase()
析构字节队列内核 / Destroy the byte-queue core
std::atomic< SequenceType > tail_
下一个待入队的逻辑位置。 Next logical enqueue position.
MPMCQueueBase(const MPMCQueueBase &)
禁止拷贝构造。 Non-copyable.
MPMCQueueBase & operator=(MPMCQueueBase &&)
禁止移动赋值。 Non-move-assignable.
size_t MaxSize() const
获取队列最大容量 / Get the maximum queue capacity
SequenceCell * sequences_
槽序号数组。 Array of per-slot sequence cells.
MPMCQueueBase & operator=(const MPMCQueueBase &)
禁止拷贝赋值。 Non-copy-assignable.
ErrorCode PushBytes(const void *value)
按字节入队一个 payload / Enqueue one payload by bytes
const size_t element_size_
单个 payload 的字节数。 Byte size of one payload.
constexpr size_t CONCURRENCY_ALIGNMENT
并发结构对齐粒度(用于降低多核伪共享) / Alignment policy used by concurrency-oriented structures
每个逻辑槽对应的序号单元。 Sequence cell for one logical slot.
std::atomic< SequenceType > value
当前槽的逻辑序号。 Current logical sequence of the slot.