1#include "write_port.hpp"
17 if (buffered_size_ != 0U)
19 UNUSED(SubmitBuffered());
37 if (!port_->Writable())
41 if (!port_->TryClaimProducer())
46 if (!port_->IsAdmissionMode() && port_->queue_requests_->EmptySize() < 1U)
48 port_->ReleaseProducer(WritePort::Phase::IDLE,
false);
58 if (port_ ==
nullptr || !port_->Writable())
68 const ErrorCode acquire_result = Acquire();
71 return acquire_result;
74 ASSERT(data.
addr_ !=
nullptr);
76 if (port_->queue_data_ ==
nullptr || port_->queue_data_->EmptySize() < data.
size_)
81 [[maybe_unused]]
const ErrorCode result = port_->queue_data_->PushBatch(
82 reinterpret_cast<const uint8_t*
>(data.
addr_), data.
size_);
84 buffered_size_ += data.
size_;
88ErrorCode WritePort::Stream::SubmitBuffered()
90 DEV_ASSERT(owns_port_);
91 DEV_ASSERT(buffered_size_ != 0U);
93 const size_t size = buffered_size_;
96 return port_->IsAdmissionMode() ? port_->CommitAdmission(size, op_,
false)
97 : port_->CommitQueued(size, op_,
false);
100void WritePort::Stream::Release()
106 DEV_ASSERT(buffered_size_ == 0U);
108 port_->ReleaseProducer(WritePort::Phase::IDLE,
false);
111void WritePort::Stream::CompleteEmpty()
113 if (op_.type != WriteOperation::OperationType::BLOCK)
134 if (buffered_size_ != 0U)
136 return SubmitBuffered();
只读原始数据视图 / Immutable raw data view
size_t size_
数据字节数 / Data size in bytes
const void * addr_
数据起始地址 / Data start address
合并多次写入的流接口 / Stream interface for batched writes.
ErrorCode Acquire()
尝试取得端口写入权 / Try to acquire the port's producer access.
ErrorCode Commit()
提交批次并释放写入权 / Submit the batch and release producer access.
Stream(WritePort *port, WriteOperation op)
构造流并尝试取得写入权 / Construct a stream and try to acquire the port.
~Stream()
提交剩余批次并结束流 / Submit the remaining batch and destroy the stream.
ErrorCode Write(ConstRawData data)
向当前批次追加数据 / Append data to the current batch.
Stream & operator<<(const ConstRawData &data)
尝试追加数据并返回流引用 / Try to append data and return the stream.
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
size_t EmptySize() const
获取字节队列当前空闲空间 / Get current byte queue free space.
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ PTR_NULL
空指针 / Null pointer
@ NOT_SUPPORT
不支持 / Not supported
@ OK
操作成功 / Operation successful