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)
155 if (op.
type != WriteOperation::OperationType::BLOCK)
159 else if (meta_pushed)
164 if (op.
type == WriteOperation::OperationType::BLOCK)
168 std::memory_order_acq_rel,
169 std::memory_order_acquire))
179 if (op.
type == WriteOperation::OperationType::BLOCK)
181 auto state =
busy_.load(std::memory_order_acquire);
184 state =
busy_.load(std::memory_order_acquire);
189 auto finish_wait_ans = op.
data.sem_info.sem->
Wait(UINT32_MAX);
190 UNUSED(finish_wait_ans);
213 if (op.
type != WriteOperation::OperationType::BLOCK)
220 if (op.
type == WriteOperation::OperationType::BLOCK)
223 auto wait_ans = op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
228#ifdef LIBXR_DEBUG_BUILD
229 auto state =
busy_.load(std::memory_order_acquire);
240 std::memory_order_acq_rel,
241 std::memory_order_acquire))
250 expected =
busy_.load(std::memory_order_acquire);
268 auto finish_wait_ans = op.
data.sem_info.sem->
Wait(UINT32_MAX);
269 UNUSED(finish_wait_ans);
291 auto state =
busy_.load(std::memory_order_acquire);
295 DEV_ASSERT_FROM_CALLBACK(
false, in_isr);
301 DEV_ASSERT_FROM_CALLBACK(
false, in_isr);
307 DEV_ASSERT_FROM_CALLBACK(
false, in_isr);
315 std::memory_order_acq_rel,
316 std::memory_order_acquire))
324 Finish(in_isr, reason, info);
341 Finish(in_isr, reason, info);
357 Finish(in_isr, reason, info);
只读原始数据视图 / Immutable raw data view
size_t size_
数据字节数 / Data size in bytes
const void * addr_
数据起始地址 / Data start address
无锁队列实现 / Lock-free queue implementation
void Reset()
重置队列 / Resets the queue
ErrorCode PushBatch(const Data *data, size_t size)
批量推入数据 / Pushes multiple elements into the queue
size_t EmptySize()
计算队列剩余可用空间 / Calculates the remaining available space in the queue
size_t Size() const
获取当前队列中的元素数量 / Returns the number of elements currently in the queue
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.
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.
ErrorCode block_result_
Final status for the current BLOCK write. 当前 BLOCK 写入的最终结果。
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. 提交路径占有写队列/元数据修改权。
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.
LockFreeQueue< uint8_t > * queue_data_
Payload queue for pending write bytes. 挂起写入字节的数据队列。
LockFreeQueue< WriteInfoBlock > * queue_info_
Metadata queue for pending write batches. 挂起写批次的元数据队列。
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 CACHE_LINE_SIZE
缓存行大小 / Cache line size
WriteOperation op
Write operation instance. 写入操作实例。