1#include "write_port.hpp"
41 if (info.
op.
type == WriteOperation::OperationType::BLOCK)
49 std::memory_order_acq_rel,
50 std::memory_order_acquire))
63 std::memory_order_acq_rel,
64 std::memory_order_acquire))
77 std::memory_order_acq_rel,
78 std::memory_order_acquire);
94 if (op.
type != WriteOperation::OperationType::BLOCK)
103 std::memory_order_acq_rel,
104 std::memory_order_acquire))
140 if (op.
type == WriteOperation::OperationType::BLOCK)
164 if (op.
type != WriteOperation::OperationType::BLOCK)
168 else if (meta_pushed)
173 if (op.
type == WriteOperation::OperationType::BLOCK)
177 std::memory_order_acq_rel,
178 std::memory_order_acquire))
188 if (op.
type == WriteOperation::OperationType::BLOCK)
190 auto state =
busy_.load(std::memory_order_acquire);
193 state =
busy_.load(std::memory_order_acquire);
198 auto finish_wait_ans = op.
data.sem_info.sem->
Wait(UINT32_MAX);
199 UNUSED(finish_wait_ans);
222 if (op.
type != WriteOperation::OperationType::BLOCK)
229 if (op.
type == WriteOperation::OperationType::BLOCK)
232 auto wait_ans = op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
237#ifdef LIBXR_DEBUG_BUILD
238 auto state =
busy_.load(std::memory_order_acquire);
249 std::memory_order_acq_rel,
250 std::memory_order_acquire))
259 expected =
busy_.load(std::memory_order_acquire);
277 auto finish_wait_ans = op.
data.sem_info.sem->
Wait(UINT32_MAX);
278 UNUSED(finish_wait_ans);
300 auto state =
busy_.load(std::memory_order_acquire);
304 DEV_ASSERT_FROM_CALLBACK(
false, in_isr);
310 DEV_ASSERT_FROM_CALLBACK(
false, in_isr);
316 DEV_ASSERT_FROM_CALLBACK(
false, in_isr);
324 std::memory_order_acq_rel,
325 std::memory_order_acquire))
333 Finish(in_isr, reason, info);
350 Finish(in_isr, reason, info);
366 Finish(in_isr, reason, info);
只读原始数据视图 / Immutable raw data view
size_t size_
数据字节数 / Data size in bytes
const void * addr_
数据起始地址 / Data start address
union LibXR::Operation::@5 data
void UpdateStatus(bool in_isr, Status &&status)
Updates operation status based on type.
void MarkAsRunning()
标记操作为运行状态。 Marks the operation as running.
size_t Size() const
获取当前已用元素数 / Get the current element count
size_t EmptySize() const
获取剩余空槽数 / Get the current free-slot count
ErrorCode PushBatch(const Data *data, size_t size)
批量推入多个 payload。
void PostFromCallback(bool in_isr)
从中断回调中释放(增加)信号量 Releases (increments) the semaphore from an ISR (Interrupt Service Routine)
ErrorCode Wait(uint32_t timeout=UINT32_MAX)
等待(减少)信号量 Waits (decrements) the semaphore
WritePort class for handling write operations.
size_t EmptySize()
获取数据队列的剩余可用空间。 Gets the remaining available space in the data queue.
void FailAndClearAll(ErrorCode reason, bool in_isr)
失败完成并清空当前所有挂起写操作。
size_t Size()
获取当前数据队列的已使用大小。 Gets the used size of the current data queue.
void Finish(bool in_isr, ErrorCode ans, WriteInfoBlock &info)
更新写入操作的状态。 Updates the status of the write operation.
SPSCQueue< WriteInfoBlock > * queue_info_
Metadata queue for pending write batches. 挂起写批次的元数据队列。
WritePort(size_t queue_size=3, size_t buffer_size=128)
构造一个新的 WritePort 对象。 Constructs a new WritePort object.
WritePort & operator=(WriteFun fun)
赋值运算符重载,用于设置写入函数。 Overloaded assignment operator to set the write function.
std::atomic< BusyState > busy_
Shared submit/wait handoff state. 共享的提交/等待交接状态。
@ BLOCK_CLAIMED
Final wakeup belongs to the current waiter. 最终唤醒已归当前等待者所有。
@ LOCKED
Submission path owns queue mutation. 提交路径占有写队列/元数据修改权。
SPSCQueue< uint8_t > * queue_data_
Payload queue for pending write bytes. 挂起写入字节的数据队列。
bool Writable()
判断端口是否可写。 Checks whether the port is writable.
WriteFun write_fun_
Driver/backend write entry. 底层驱动或后端写入入口。
ErrorCode CommitWrite(ConstRawData data, WriteOperation &op, bool pushed=false, bool in_isr=false)
提交写入操作。 Commits a write operation.
void MarkAsRunning(WriteOperation &op)
标记写入操作为运行中。 Marks the write operation as running.
ErrorCode operator()(ConstRawData data, WriteOperation &op, bool in_isr=false)
执行写入操作。 Performs a write operation.
@ NOT_SUPPORT
不支持 | Not supported
@ OK
操作成功 | Operation successful
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.
constexpr size_t CONCURRENCY_ALIGNMENT
并发结构对齐粒度(用于降低多核伪共享) / Alignment policy used by concurrency-oriented structures
WriteOperation op
Write operation instance. 写入操作实例。