10ErrorCode STDIO::CompiledSink::Write(std::string_view chunk)
23 size_t copy_size = chunk.size();
24 size_t stream_writable = stream_.
EmptySize();
25 if (copy_size > stream_writable)
27 copy_size = stream_writable;
37 ec = stream_.
Write(std::string_view(chunk.data(), copy_size));
43 retained_size_ += copy_size;
44 if (copy_size != chunk.size() || stream_.
EmptySize() == 0)
51bool STDIO::BeginWriteSession()
67 CompiledWriteFun write_fun)
69 CompiledSink sink(stream);
70 auto ec = write_fun(context, sink);
71 return FinishWriteSession(stream, sink.RetainedSize(), ec);
74int STDIO::WriteCompiledSession(
void* context, CompiledWriteFun write_fun)
77 DEV_ASSERT(write_fun !=
nullptr);
81 return WriteCompiledToStream(*
write_stream_, context, write_fun);
86 return WriteCompiledToStream(stream, context, write_fun);
104 retained_size >
static_cast<size_t>(std::numeric_limits<int>::max()))
109 return static_cast<int>(retained_size);
互斥锁类,提供线程同步机制 Mutex class providing thread synchronization mechanisms.
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 Lock the mutex, blocking if it is already locked.
void Unlock()
解锁互斥锁 Unlock the mutex.
static LibXR::WritePort::Stream * write_stream_
可选的外部托管写流 / Optional externally owned write stream.
static LibXR::Mutex * write_mutex_
写入端口互斥锁 / Write port mutex.
static WritePort * write_
写入端口 / Write port instance.
合并多次写入的流接口 / Stream interface for batched writes.
ErrorCode Acquire()
尝试取得端口写入权 / Try to acquire the port's producer access.
ErrorCode Commit()
提交批次并释放写入权 / Submit the batch and release producer access.
size_t EmptySize() const
获取当前批次可追加的空间 / Get current free space for appending.
ErrorCode Write(ConstRawData data)
向当前批次追加数据 / Append data to the current batch.
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ OK
操作成功 / Operation successful