|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue. More...
#include <write_port.hpp>
Classes | |
| class | Stream |
| 合并多次写入的流接口 / Stream interface for batched writes. More... | |
| class | WriteQueue |
| 已提交队头的出队接口 / Consumer interface for one released front. More... | |
Public Member Functions | |
| WritePort (size_t queue_size=3U, size_t buffer_size=128U) | |
| 构造写端口并分配队列 / Construct a write port and allocate its queues. | |
| size_t | EmptySize () const |
| 获取字节队列当前空闲空间 / Get current byte queue free space. | |
| size_t | Size () const |
| 获取字节队列当前数据量 / Get current byte queue occupancy. | |
| size_t | Capacity () const |
| 获取字节队列总容量 / Get total byte queue capacity. | |
| bool | Writable () const |
| 检查端口是否支持写入 / Check whether the port supports writes. | |
| WritePort & | operator= (WriteFun fun) |
| 绑定写入进度通知函数 / Bind the write progress notification function. | |
| WriteQueue | GetWriteQueue (bool in_isr=false) |
| 获取已提交队头的出队接口 / Obtain a consumer interface for the released front. | |
| ErrorCode | operator() (ConstRawData data, WriteOperation &op, bool in_isr=false) |
| 提交写请求 / Submit a write request. | |
Friends | |
| class | Pipe |
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
普通后端按请求顺序取走数据,整个请求被后端接收后完成;Pipe 共用读写字节队列, 写入队列后即可完成。调用者的数据会复制到队列,完成通知对象仍由调用者持有。 Queued backends consume requests in FIFO order and complete each after accepting all its bytes. Pipe shares the byte queue with its reader and completes writes on admission. Payload is copied; completion targets remain caller-owned.
Definition at line 39 of file write_port.hpp.
| WritePort::WritePort | ( | size_t | queue_size = 3U, |
| size_t | buffer_size = 128U ) |
构造写端口并分配队列 / Construct a write port and allocate its queues.
| queue_size | 请求队列容量;正数采用后端逐请求完成模式,零采用 Pipe 使用的 入队即完成模式,不分配请求队列。最大值为 2^29 - 1。 Request capacity; positive selects queued completion, zero selects the admission completion used by Pipe, with no metadata. Maximum: 2^29 - 1. |
| buffer_size | 字节队列容量;零表示不分配字节存储。 Byte queue capacity; zero allocates no payload storage. |
Definition at line 8 of file write_port.cpp.
|
nodiscard |
获取字节队列总容量 / Get total byte queue capacity.
Definition at line 29 of file write_port.cpp.
|
nodiscard |
获取字节队列当前空闲空间 / Get current byte queue free space.
Definition at line 19 of file write_port.cpp.
|
nodiscard |
获取已提交队头的出队接口 / Obtain a consumer interface for the released front.
| in_isr | 当前是否在中断中;本次析构结算和完成通知使用该上下文。 ISR context, captured for settlement and completion notifications. |
Definition at line 119 of file write_port.cpp.
| ErrorCode WritePort::operator() | ( | ConstRawData | data, |
| WriteOperation & | op, | ||
| bool | in_isr = false ) |
提交写请求 / Submit a write request.
| data | 数据源和字节数;正长度地址须有效,接纳时在本次调用内完整复制到队列, 返回后即可复用源缓冲区。 零长度允许空地址,在能力检查后立即成功,不通知后端,非 BLOCK 同步完成。 Source and byte count; admitted data is fully copied during this call. A positive size requires a valid address; the source is reusable after return. Zero size permits null and succeeds after the capability check, without backend notification, completing non-BLOCK inline. |
| op | 完成通知描述符;回调和轮询状态须保持到完成,BLOCK 信号量须保持到返回。 Completion descriptor; keep callback and polling targets through completion and the BLOCK semaphore through return. |
| in_isr | 当前调用是否位于中断 / Whether this call is in an ISR. |
Definition at line 449 of file write_port.cpp.
绑定写入进度通知函数 / Bind the write progress notification function.
| fun | 接收端口和当前中断上下文的通知函数,不返回请求完成结果。 Notification receiving the port and ISR context, without a completion result. |
Definition at line 39 of file write_port.cpp.
|
nodiscard |
获取字节队列当前数据量 / Get current byte queue occupancy.
Definition at line 24 of file write_port.cpp.
|
nodiscard |
检查端口是否支持写入 / Check whether the port supports writes.
Definition at line 34 of file write_port.cpp.
|
friend |
Definition at line 131 of file write_port.hpp.