8#include "lockfree_queue.hpp"
9#include "operation.hpp"
205 WritePort(
size_t queue_size = 3,
size_t buffer_size = 128);
336 bool in_isr =
false);
只读原始数据视图 / Immutable raw data view
无锁队列实现 / Lock-free queue implementation
ErrorCode SubmitBuffered()
将当前已缓存批次提交给 WritePort。
ErrorCode Acquire()
为当前流批次获取一次可写入的端口所有权。
ErrorCode Commit()
手动提交已写入的数据到队列,并释放当前锁。
size_t batch_capacity_
当前批次可用的总容量 Total capacity reserved for the current batch
void Release()
将当前批次的端口所有权归还给 WritePort。
size_t EmptySize() const
获取当前批次还可追加的剩余字节数。
LibXR::WritePort * port_
写端口指针 Pointer to the WritePort
LibXR::WriteOperation op_
写操作对象 Write operation object
~Stream()
析构时自动提交已累积的数据并释放锁。
bool owns_port_
当前 Stream 是否持有该批次的端口所有权 Whether this Stream currently owns the batch
size_t buffered_size_
当前批次已追加到共享 data queue、但尚未发布对应元数据的字节数 Bytes already appended into the shared data queue for the curren...
ErrorCode Write(ConstRawData data)
追加一个原始数据片段到当前流批次。
ErrorCode Write(std::string_view text)
追加一个文本片段到当前流批次。
Stream(LibXR::WritePort *port, LibXR::WriteOperation op)
构造流写入对象,并尝试锁定端口。
Stream & operator<<(const ConstRawData &data)
追加写入数据的语法糖,忽略返回状态并支持链式调用。
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.
@ OK
操作成功 | Operation successful
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.