1#include "read_port.hpp"
36 if (info.
op.
type == ReadOperation::OperationType::BLOCK)
71 if (readable_size >= data.
size_ && readable_size != 0)
81 if (op.
type != ReadOperation::OperationType::BLOCK)
94 std::memory_order_acq_rel,
95 std::memory_order_acquire))
102 if (
static_cast<int8_t
>(ans) >= 0)
112 std::memory_order_acq_rel,
113 std::memory_order_acquire))
115 if (op.
type != ReadOperation::OperationType::BLOCK)
131 ASSERT(op.
type != ReadOperation::OperationType::BLOCK);
138 if (op.
type == ReadOperation::OperationType::BLOCK)
141 auto wait_ans = op.
data.sem_info.sem->
Wait(op.
data.sem_info.timeout);
146#ifdef LIBXR_DEBUG_BUILD
147 auto state =
busy_.load(std::memory_order_acquire);
159 std::memory_order_acq_rel,
160 std::memory_order_acquire))
177 auto finish_wait_ans = op.
data.sem_info.sem->
Wait(UINT32_MAX);
178 UNUSED(finish_wait_ans);
200 auto is_busy =
busy_.load(std::memory_order_acquire);
207 if (
info_.
op.
type == ReadOperation::OperationType::BLOCK)
213 std::memory_order_acq_rel,
214 std::memory_order_acquire))
245 std::memory_order_acq_rel,
246 std::memory_order_acquire))
262 auto state =
busy_.load(std::memory_order_acquire);
265 if (
info_.
op.
type == ReadOperation::OperationType::BLOCK)
273 std::memory_order_acq_rel,
274 std::memory_order_acquire))
无锁队列实现 / Lock-free queue implementation
void Reset()
重置队列 / Resets 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
ErrorCode PopBatch(Data *data, size_t size)
批量弹出数据 / Pops multiple elements from 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.
可写原始数据视图 / Mutable raw data view
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address
ReadPort class for handling read operations.
bool Readable()
Checks if read operations are supported.
ReadFun read_fun_
Driver/backend read notification entry. 底层驱动或后端读取通知入口。
void Finish(bool in_isr, ErrorCode ans, ReadInfoBlock &info)
完成已由队列路径认领的读取操作。 Completes a read operation already claimed by the queue path.
ReadPort(size_t buffer_size=128)
Constructs a ReadPort with queue sizes.
ErrorCode block_result_
Final status for the current BLOCK read.
@ IDLE
No active waiter and no pending completion. 无等待者、无挂起完成。
std::atomic< BusyState > busy_
Shared read-progress handoff state. 共享的读进度交接状态。
size_t EmptySize()
获取队列的剩余可用空间。 Gets the remaining available space in the queue.
LockFreeQueue< uint8_t > * queue_data_
RX payload queue. 接收数据字节队列。
ErrorCode operator()(RawData data, ReadOperation &op, bool in_isr=false)
读取操作符重载,用于执行读取操作。 Overloaded function call operator to perform a read operation.
void ProcessPendingReads(bool in_isr)
Processes pending reads.
ReadPort & operator=(ReadFun fun)
赋值运算符重载,用于设置读取函数。 Overloaded assignment operator to set the read function.
size_t Size()
获取当前队列的已使用大小。 Gets the currently used size of the queue.
void FailAndClearAll(ErrorCode reason, bool in_isr)
失败完成并清空当前所有挂起读操作。
virtual void OnRxDequeue(bool)
RX 数据从软件队列成功出队后的通知。 Notification after bytes are popped from RX data queue.
ReadInfoBlock info_
In-flight read request metadata. 当前在途读取请求的元数据。
void MarkAsRunning(ReadInfoBlock &info)
标记读取操作为运行中。 Marks the read 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
@ NOT_SUPPORT
不支持 | Not supported
@ OK
操作成功 | Operation successful
ErrorCode(* ReadFun)(ReadPort &port, bool in_isr)
Function pointer type for read notifications.
constexpr size_t CACHE_LINE_SIZE
缓存行大小 / Cache line size
Read information block structure.
RawData data
Data buffer. 数据缓冲区。
ReadOperation op
Read operation instance. 读取操作实例。