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 81 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

CallbackBlock 一样,这里直接接收精确的函数指针类型。 Same as CallbackBlock, this constructor takes the exact callback function-pointer type directly.

Definition at line 91 of file libxr_cb.hpp.

93 : CallbackBlock<ArgType, Args...>(fun, std::move(arg))
94 {
95 this->run_fun_ = &InvokeThunk;
96 }
CallbackBlock(FunctionType fun, ArgType &&arg)
Definition libxr_cb.hpp:49

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 98 of file libxr_cb.hpp.

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

Field Documentation

◆ pending_

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

Definition at line 128 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 129 of file libxr_cb.hpp.

129{};

◆ running_

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

Definition at line 127 of file libxr_cb.hpp.


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