|
libxr
1.0
Want to be the best embedded framework
|
合并通知并串行执行服务函数 / Coalesce notifications and serialize service execution More...
#include <serialized_service.hpp>
Public Member Functions | |
| template<typename Handler > | |
| bool | Invoke (uint32_t events, Handler &&handler) noexcept |
| 发布事件并尝试执行服务 / Publish events and try to run the service | |
| SerializedService (const SerializedService &)=delete | |
| SerializedService & | operator= (const SerializedService &)=delete |
Private Attributes | |
| std::atomic< uint32_t > | state_ {0U} |
Static Private Attributes | |
| static constexpr uint32_t | OWNER_BIT = 1U << 31U |
| static constexpr uint32_t | EVENT_MASK = ~OWNER_BIT |
合并通知并串行执行服务函数 / Coalesce notifications and serialize service execution
每次调用先把事件合并进一个 32 位状态字,再竞争同一状态字中的唯一 owner 位。未取得 owner 的调用立即返回;owner 原子取走事件快照并执行 handler,直到没有待处理事件。 handler 执行期间再次调用 Invoke() 只会留下下一轮事件,不会递归执行 handler。 Each invocation first merges events into one 32-bit state word and then competes for the sole owner bit in that same word. A caller that does not acquire ownership returns immediately. The owner atomically consumes event snapshots and runs the handler until no work remains. Reentrant Invoke() calls only schedule another round; they never invoke the handler recursively.
Definition at line 33 of file serialized_service.hpp.
|
inlinenoexcept |
发布事件并尝试执行服务 / Publish events and try to run the service
| Handler | 可调用对象类型,签名为 void(uint32_t) / Callable type with the signature void(uint32_t) |
| events | 要合并的低 31 位非零事件位图 / Nonzero low-31-bit event mask to merge |
| handler | 处理每轮事件快照的服务函数 / Service function handling each snapshot |
Definition at line 48 of file serialized_service.hpp.
|
staticconstexprprivate |
Definition at line 104 of file serialized_service.hpp.
|
staticconstexprprivate |
Definition at line 103 of file serialized_service.hpp.
|
private |
Definition at line 106 of file serialized_service.hpp.