libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::GuardedCallbackBlock< ArgType, Args > Class Template Reference
Inheritance diagram for LibXR::GuardedCallbackBlock< ArgType, Args >:
[legend]
Collaboration diagram for LibXR::GuardedCallbackBlock< ArgType, Args >:
[legend]

Public Member Functions

 GuardedCallbackBlock (typename CallbackBlock< ArgType, Args... >::FunctionType fun, ArgType &&arg)
 带防重入保护的回调块 / Callback block with reentry guard
 
- Public Member Functions inherited from LibXR::CallbackBlock< ArgType, Args... >
 CallbackBlock (FunctionType fun, ArgType &&arg)
 构造回调块,绑定回调函数与参数 / Construct a callback block with bound function and argument
 
 CallbackBlock (const CallbackBlock &other)=delete
 禁用拷贝构造与拷贝赋值 / Copy construction and copy assignment are disabled
 
CallbackBlockoperator= (const CallbackBlock &other)=delete
 

Static Public Member Functions

static void InvokeThunk (void *cb_block, bool in_isr, Args... args)
 
- Static Public Member Functions inherited from LibXR::CallbackBlock< ArgType, Args... >
static void InvokeThunk (void *cb_block, bool in_isr, Args... args)
 

Private Attributes

bool running_ = false
 
bool pending_ = false
 
std::tuple< std::decay_t< Args >... > pending_args_ {}
 

Additional Inherited Members

- Public Types inherited from LibXR::CallbackBlock< ArgType, Args... >
using FunctionType
 回调函数类型定义 / Callback function type definition
 
- Public Types inherited from LibXR::CallbackBlockHeader< Args... >
using InvokeFunType
 
- Data Fields inherited from LibXR::CallbackBlockHeader< Args... >
InvokeFunType run_fun_
 
- Protected Member Functions inherited from LibXR::CallbackBlock< ArgType, Args... >
void Invoke (bool in_isr, Args... args)
 
- Protected Attributes inherited from LibXR::CallbackBlock< ArgType, Args... >
FunctionType fun_
 绑定的回调函数 / Bound callback function
 
ArgType arg_
 绑定的参数 / Bound argument
 

Detailed Description

template<typename ArgType, typename... Args>
class LibXR::GuardedCallbackBlock< ArgType, Args >

Definition at line 84 of file libxr_cb.hpp.

Constructor & Destructor Documentation

◆ GuardedCallbackBlock()

template<typename ArgType , typename... Args>
LibXR::GuardedCallbackBlock< ArgType, Args >::GuardedCallbackBlock ( typename CallbackBlock< ArgType, Args... >::FunctionType fun,
ArgType && arg )
inline

带防重入保护的回调块 / Callback block with reentry guard

Note
该保护层只负责压平同一回调的递归重入链路, 不承担通用的跨上下文同步语义。 This guard only flattens self-recursive callback chains and does not provide general cross-context synchronization semantics.

Definition at line 95 of file libxr_cb.hpp.

97 : CallbackBlock<ArgType, Args...>(fun, std::move(arg))
98 {
99 this->run_fun_ = &InvokeThunk;
100 }
CallbackBlock(FunctionType fun, ArgType &&arg)
Definition libxr_cb.hpp:55

Member Function Documentation

◆ InvokeThunk()

template<typename ArgType , typename... Args>
static void LibXR::GuardedCallbackBlock< ArgType, Args >::InvokeThunk ( void * cb_block,
bool in_isr,
Args... args )
inlinestatic

Definition at line 102 of file libxr_cb.hpp.

103 {
104 auto* cb = static_cast<GuardedCallbackBlock<ArgType, Args...>*>(cb_block);
105
106 if (!cb->running_)
107 {
108 cb->running_ = true;
109 auto cur_args = std::tuple<std::decay_t<Args>...>{std::forward<Args>(args)...};
110 do
111 {
112 cb->pending_ = false;
113 std::apply([&](auto&... a) { cb->Invoke(in_isr, a...); }, cur_args);
114 if (cb->pending_)
115 {
116 cur_args = std::move(cb->pending_args_);
117 }
118 } while (cb->pending_);
119 cb->running_ = false;
120 return;
121 }
122
123 // 重入时只保留最新一组参数,把递归调用压平成串行重放。
124 // On reentry, keep only the latest argument pack so recursive callback chains are
125 // flattened into serialized replay.
126 cb->pending_args_ = std::tuple<std::decay_t<Args>...>{std::forward<Args>(args)...};
127 cb->pending_ = true;
128 }
GuardedCallbackBlock(typename CallbackBlock< ArgType, Args... >::FunctionType fun, ArgType &&arg)
带防重入保护的回调块 / Callback block with reentry guard
Definition libxr_cb.hpp:95

Field Documentation

◆ pending_

template<typename ArgType , typename... Args>
bool LibXR::GuardedCallbackBlock< ArgType, Args >::pending_ = false
private

Definition at line 132 of file libxr_cb.hpp.

◆ pending_args_

template<typename ArgType , typename... Args>
std::tuple<std::decay_t<Args>...> LibXR::GuardedCallbackBlock< ArgType, Args >::pending_args_ {}
private

Definition at line 133 of file libxr_cb.hpp.

133{};

◆ running_

template<typename ArgType , typename... Args>
bool LibXR::GuardedCallbackBlock< ArgType, Args >::running_ = false
private

Definition at line 131 of file libxr_cb.hpp.


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