libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Pipe Class Reference

由读写端口组成的单向管道 / Unidirectional pipe connecting read and write ports. More...

#include <libxr_pipe.hpp>

Public Member Functions

 Pipe (size_t buffer_size)
 构造管道并绑定共享队列 / Construct a pipe and bind its shared queue.
 
 ~Pipe ()=default
 析构管道 / Destroy the pipe.
 
 Pipe (const Pipe &)=delete
 端口状态与共享队列不可复制 / Endpoint state and the shared queue cannot be copied.
 
Pipe & operator= (const Pipe &)=delete
 
ReadPort & GetReadPort ()
 获取读端口 / Get the read endpoint.
 
WritePort & GetWritePort ()
 获取写端口 / Get the write endpoint.
 

Detailed Description

由读写端口组成的单向管道 / Unidirectional pipe connecting read and write ports.

写端分配一条 SPSC 字节队列,读端借用该队列,两端之间无需再次复制数据。 写操作在数据入队并通知读端后完成,无需等待读端消费全部数据。 The writer allocates one SPSC byte queue shared with the reader, without another copy between endpoints. Writes complete after admission and reader notification, without waiting for all bytes to be read.

Note
Stream 追加的字节在 Commit 前即可被读端读取,Commit 负责通知挂起读。 Stream appends are readable before Commit, which notifies pending reads.
Precondition
两端遵守 ReadPort 和 WritePort 的调用约定。读端只负责消费共享队列。 Both endpoints follow their port contracts; the reader only consumes the queue.

Definition at line 29 of file libxr_pipe.hpp.

Constructor & Destructor Documentation

◆ Pipe()

LibXR::Pipe::Pipe ( size_t buffer_size)
inlineexplicit

构造管道并绑定共享队列 / Construct a pipe and bind its shared queue.

Parameters
buffer_size共享队列容量,单位为字节,必须大于零。 Shared queue capacity in bytes, which must be positive.
Note
仅分配字节队列 / Allocates only the byte queue.

Definition at line 38 of file libxr_pipe.hpp.

38 : read_port_(0), write_port_(0, buffer_size)
39 {
40 ASSERT(write_port_.queue_data_ != nullptr);
41 read_port_.BindQueue(write_port_.queue_data_);
42 write_port_ = &WriteFun;
43 }
void(* WriteFun)(WritePort &port, bool in_isr)
写入进度通知函数类型 / Write progress notification function type.

◆ ~Pipe()

LibXR::Pipe::~Pipe ( )
default

析构管道 / Destroy the pipe.

Precondition
相关请求、调用、回调及持有写入权的 Stream 已结束。 Related requests, calls, callbacks, and owning Streams have ended.
Note
不取消请求,也不释放队列存储 / Does not cancel requests or free queue storage.

Member Function Documentation

◆ GetReadPort()

ReadPort & LibXR::Pipe::GetReadPort ( )
inline

获取读端口 / Get the read endpoint.

Returns
管道内部读端口的引用 / Reference to the pipe's read port.

Definition at line 61 of file libxr_pipe.hpp.

61{ return read_port_; }

◆ GetWritePort()

WritePort & LibXR::Pipe::GetWritePort ( )
inline

获取写端口 / Get the write endpoint.

Returns
管道内部写端口的引用 / Reference to the pipe's write port.

Definition at line 67 of file libxr_pipe.hpp.

67{ return write_port_; }

The documentation for this class was generated from the following file: