libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Operation< Args > Class Template Reference

操作的完成通知描述符 / Completion notification descriptor for an operation. More...

#include <operation.hpp>

Collaboration diagram for LibXR::Operation< Args >:
[legend]

Public Types

enum class  OperationType : uint8_t { CALLBACK , BLOCK , POLLING , NONE }
 完成通知方式 / Completion notification mode. More...
 
enum class  OperationPollingStatus : uint32_t { READY , RUNNING , DONE , ERROR }
 
using Callback = LibXR::Callback<Args>
 

Public Member Functions

 Operation ()
 构造无完成通知的操作 / Construct an operation without notification.
 
 Operation (Semaphore &sem, uint32_t timeout=UINT32_MAX)
 构造阻塞操作 / Construct a blocking operation.
 
 Operation (Callback &callback)
 构造回调操作 / Construct a callback operation.
 
 Operation (std::atomic< OperationPollingStatus > &status)
 构造轮询操作 / Construct a polling operation.
 
 Operation (const Operation &)=default
 复制通知描述符,共用通知对象 / Copy the descriptor, sharing notification targets.
 
 Operation (Operation &&) noexcept=default
 移动描述符,源描述符保持不变 / Move the descriptor without clearing the source.
 
Operation & operator= (const Operation &)=default
 复制通知描述符 / Copy the notification descriptor.
 
Operation & operator= (Operation &&) noexcept=default
 移动通知描述符 / Move the notification descriptor.
 
template<typename Status >
void UpdateStatus (bool in_isr, Status &&status)
 按通知方式报告完成结果 / Report completion using the selected mode.
 
void MarkAsRunning ()
 标记轮询操作正在执行 / Mark a polling operation as running.
 

Public Attributes

union { 
 
   Callback *   callback 
 借用的回调对象 / Borrowed callback. More...
 
   struct { 
 
      Semaphore *   sem 
 借用的信号量 / Borrowed semaphore. More...
 
      uint32_t   timeout 
 等待超时值 / Wait timeout. More...
 
   }   sem_info 
 
   std::atomic< OperationPollingStatus > *   status 
 借用的轮询状态 / Borrowed polling status. More...
 
} data 
 完成通知对象,由 type 选择有效成员 / Notification target selected by type.
 
OperationType type
 当前通知方式 / Current notification mode.
 

Detailed Description

template<typename Args>
class LibXR::Operation< Args >

操作的完成通知描述符 / Completion notification descriptor for an operation.

Template Parameters
Args回调参数类型 / Callback argument type.
Note
复制描述符仍引用相同通知对象;调用者负责其生命周期。 Copies refer to the same notification targets; callers manage their lifetime.

Definition at line 24 of file operation.hpp.

Member Typedef Documentation

◆ Callback

template<typename Args >
using LibXR::Operation< Args >::Callback = LibXR::Callback<Args>

Definition at line 27 of file operation.hpp.

Member Enumeration Documentation

◆ OperationPollingStatus

template<typename Args >
enum class LibXR::Operation::OperationPollingStatus : uint32_t
strong

轮询操作状态;保持字宽,避免 M0 引入 byte-atomic runtime ABI / Polling status; keep it word-sized to avoid byte-atomic runtime ABI on M0.

Enumerator
READY 

尚未开始 / Not started.

RUNNING 

正在执行 / In progress.

DONE 

成功完成 / Completed successfully.

ERROR 

错误结束 / Completed with an error.

Definition at line 40 of file operation.hpp.

41 {
42 READY,
43 RUNNING,
44 DONE,
45 ERROR
46 };
@ DONE
成功完成 / Completed successfully.
@ READY
尚未开始 / Not started.
@ RUNNING
正在执行 / In progress.
@ ERROR
错误结束 / Completed with an error.

◆ OperationType

template<typename Args >
enum class LibXR::Operation::OperationType : uint8_t
strong

完成通知方式 / Completion notification mode.

Enumerator
CALLBACK 

执行回调 / Invoke a callback.

BLOCK 

信号量等待 / Wait with a semaphore.

POLLING 

查询原子状态 / Poll an atomic status.

NONE 

无完成通知 / No completion notification.

Definition at line 30 of file operation.hpp.

31 {
32 CALLBACK,
33 BLOCK,
34 POLLING,
35 NONE
36 };
@ BLOCK
信号量等待 / Wait with a semaphore.
@ NONE
无完成通知 / No completion notification.
@ CALLBACK
执行回调 / Invoke a callback.
@ POLLING
查询原子状态 / Poll an atomic status.

Constructor & Destructor Documentation

◆ Operation() [1/4]

template<typename Args >
LibXR::Operation< Args >::Operation ( )
inline

构造无完成通知的操作 / Construct an operation without notification.

Definition at line 49 of file operation.hpp.

49: data{nullptr}, type(OperationType::NONE) {}
union LibXR::Operation::@6 data
完成通知对象,由 type 选择有效成员 / Notification target selected by type.
OperationType type
当前通知方式 / Current notification mode.

◆ Operation() [2/4]

template<typename Args >
LibXR::Operation< Args >::Operation ( Semaphore & sem,
uint32_t timeout = UINT32_MAX )
inline

构造阻塞操作 / Construct a blocking operation.

Parameters
sem等待完成的信号量 / Semaphore for completion waiting.
timeout传给 Semaphore::Wait 的超时值,默认 UINT32_MAX。 Timeout passed to Semaphore::Wait; defaults to UINT32_MAX.
Precondition
信号量同时只服务一个活动 BLOCK 调用,调用返回后才可复用。 Use the semaphore for one live BLOCK call; reuse only after it returns.

Definition at line 59 of file operation.hpp.

60 : data{.sem_info = {&sem, timeout}}, type(OperationType::BLOCK)
61 {
62 }
uint32_t timeout
等待超时值 / Wait timeout.
Semaphore * sem
借用的信号量 / Borrowed semaphore.

◆ Operation() [3/4]

template<typename Args >
LibXR::Operation< Args >::Operation ( Callback & callback)
inline

构造回调操作 / Construct a callback operation.

Parameters
callback借用的完成回调 / Borrowed completion callback.

Definition at line 68 of file operation.hpp.

70 {
71 }
Callback * callback
借用的回调对象 / Borrowed callback.

◆ Operation() [4/4]

template<typename Args >
LibXR::Operation< Args >::Operation ( std::atomic< OperationPollingStatus > & status)
inline

构造轮询操作 / Construct a polling operation.

Parameters
status借用的原子状态,以 acquire 读取完成结果。 Borrowed atomic status; load completion with acquire ordering.

Definition at line 78 of file operation.hpp.

80 {
81 }
std::atomic< OperationPollingStatus > * status
借用的轮询状态 / Borrowed polling status.

Member Function Documentation

◆ MarkAsRunning()

template<typename Args >
void LibXR::Operation< Args >::MarkAsRunning ( )
inline

标记轮询操作正在执行 / Mark a polling operation as running.

Note
以 release 写入 RUNNING,其他模式不执行操作。 Stores RUNNING with release ordering; other modes are unaffected.

Definition at line 138 of file operation.hpp.

139 {
141 {
142 data.status->store(OperationPollingStatus::RUNNING, std::memory_order_release);
143 }
144 }

◆ operator=() [1/2]

template<typename Args >
Operation & LibXR::Operation< Args >::operator= ( const Operation< Args > & )
default

复制通知描述符 / Copy the notification descriptor.

Returns
当前描述符 / This descriptor.

◆ operator=() [2/2]

template<typename Args >
Operation & LibXR::Operation< Args >::operator= ( Operation< Args > && )
defaultnoexcept

移动通知描述符 / Move the notification descriptor.

Returns
当前描述符,源描述符保持不变 / This descriptor; the source remains unchanged.

◆ UpdateStatus()

template<typename Args >
template<typename Status >
void LibXR::Operation< Args >::UpdateStatus ( bool in_isr,
Status && status )
inline

按通知方式报告完成结果 / Report completion using the selected mode.

Template Parameters
Status完成结果类型 / Completion result type.
Parameters
in_isr当前是否在中断中 / Whether called in an ISR.
status传给回调或用于判断轮询成功状态的结果。 Result passed to the callback or used to set polling success or error.
Note
回调同步执行;轮询状态以 release 发布。BLOCK 仅释放信号量,NONE 无操作。 Callbacks run inline; polling uses a release store. BLOCK posts; NONE is a no-op.

Definition at line 111 of file operation.hpp.

112 {
113 switch (type)
114 {
116 data.callback->Run(in_isr, std::forward<Status>(status));
117 break;
119 // 信号量只负责唤醒,结果由调用方另行保存。
120 // The semaphore only wakes the caller; the result is stored separately.
121 data.sem_info.sem->PostFromCallback(in_isr);
122 break;
126 std::memory_order_release);
127 break;
129 break;
130 }
131 }
@ OK
操作成功 / Operation successful

Member Data Documentation

◆ callback

template<typename Args >
Callback* LibXR::Operation< Args >::callback

借用的回调对象 / Borrowed callback.

Definition at line 149 of file operation.hpp.

◆ sem

template<typename Args >
Semaphore* LibXR::Operation< Args >::sem

借用的信号量 / Borrowed semaphore.

Definition at line 152 of file operation.hpp.

◆ status

template<typename Args >
std::atomic<OperationPollingStatus>* LibXR::Operation< Args >::status

借用的轮询状态 / Borrowed polling status.

Definition at line 156 of file operation.hpp.

◆ timeout

template<typename Args >
uint32_t LibXR::Operation< Args >::timeout

等待超时值 / Wait timeout.

Definition at line 153 of file operation.hpp.

◆ type

template<typename Args >
OperationType LibXR::Operation< Args >::type

当前通知方式 / Current notification mode.

Definition at line 160 of file operation.hpp.


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