libxr
1.0
Want to be the best embedded framework
|
WritePort 的流式写入操作器,支持链式 << 操作和批量提交。 More...
#include <libxr_rw.hpp>
Public Member Functions | |
Stream (LibXR::WritePort *port, LibXR::WriteOperation op) | |
构造流写入对象,并尝试锁定端口。 | |
~Stream () | |
析构时自动提交已累积的数据并释放锁。 | |
Stream & | operator<< (const ConstRawData &data) |
追加写入数据,支持链式调用。 | |
ErrorCode | Commit () |
手动提交已写入的数据到队列,并尝试续锁。 | |
Private Attributes | |
LibXR::WritePort * | port_ |
写端口指针 Pointer to the WritePort | |
LibXR::WriteOperation | op_ |
写操作对象 Write operation object | |
size_t | cap_ |
当前队列容量 Current queue capacity | |
size_t | size_ = 0 |
当前已写入但未提交的字节数 Bytes written but not yet committed | |
bool | locked_ = false |
是否持有写锁 Whether write lock is held | |
bool | fallback_to_normal_write_ = false |
WritePort 的流式写入操作器,支持链式 << 操作和批量提交。
Stream-like writer for WritePort, supporting chainable << operations and batch commit.
构造时会尝试锁定 WritePort,并批量写入,减少碎片化写操作和队列压力。 Automatically acquires the WritePort lock (if possible), enabling batch writes to reduce fragmented write operations and queue pressure.
Definition at line 427 of file libxr_rw.hpp.
WritePort::Stream::Stream | ( | LibXR::WritePort * | port, |
LibXR::WriteOperation | op ) |
构造流写入对象,并尝试锁定端口。
Constructs a Stream object and tries to acquire WritePort lock.
port | 指向 WritePort 的指针 Pointer to WritePort. |
op | 写操作对象(可重用)Write operation object (can be reused). |
Definition at line 338 of file libxr_rw.cpp.
WritePort::Stream::~Stream | ( | ) |
析构时自动提交已累积的数据并释放锁。
Destructor: automatically commits any accumulated data and releases the lock.
Definition at line 360 of file libxr_rw.cpp.
ErrorCode WritePort::Stream::Commit | ( | ) |
手动提交已写入的数据到队列,并尝试续锁。
Manually commit accumulated data to the queue, and try to extend the lock.
调用后已写入数据会立即入队,size 计数归零。适合周期性手动 flush。 After calling, written data is enqueued, size counter reset. Suitable for periodic manual flush.
ErrorCode
,指示操作结果。 Returns an ErrorCode
indicating the result of the operation. Definition at line 402 of file libxr_rw.cpp.
WritePort::Stream & WritePort::Stream::operator<< | ( | const ConstRawData & | data | ) |
追加写入数据,支持链式调用。
Appends data for writing, supporting chain calls.
data | 要写入的数据 Data to write. |
Definition at line 370 of file libxr_rw.cpp.
|
private |
当前队列容量 Current queue capacity
Definition at line 469 of file libxr_rw.hpp.
|
private |
回退为普通写模式(不可批量) Fallback to normal write (if batch not supported)
Definition at line 472 of file libxr_rw.hpp.
|
private |
是否持有写锁 Whether write lock is held
Definition at line 471 of file libxr_rw.hpp.
|
private |
写操作对象 Write operation object
Definition at line 468 of file libxr_rw.hpp.
|
private |
写端口指针 Pointer to the WritePort
Definition at line 467 of file libxr_rw.hpp.
|
private |
当前已写入但未提交的字节数 Bytes written but not yet committed
Definition at line 470 of file libxr_rw.hpp.