NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::strand类 参考

串行化执行器 更多...

#include <strand.hpp>

Public 类型

using handler_type = function<void()>
 handler 类型

Public 成员函数

 strand (io_context &ctx)
 构造 strand
void post (handler_type handler)
 投递 handler 到 strand 队列末尾
void dispatch (handler_type handler)
 尽可能在当前线程同步执行 handler
io_context::executor get_executor () const noexcept
 获取关联的 io_context 执行器
io_contextcontext () const noexcept
 获取关联的 io_context 引用

详细描述

串行化执行器

所有投递到 strand 的 handler 严格串行执行,无需显式加锁。

在文件 strand.hpp30 行定义.

构造及析构函数说明

◆ strand()

neforce::strand::strand ( io_context & ctx)
inlineexplicit

构造 strand

参数
ctx关联的 io_context

strand 绑定到指定的 io_context。

在文件 strand.hpp72 行定义.

引用了 neforce::make_shared().

成员函数说明

◆ context()

io_context & neforce::strand::context ( ) const
inlinenodiscardnoexcept

获取关联的 io_context 引用

返回
io_context 引用

在文件 strand.hpp114 行定义.

◆ dispatch()

void neforce::strand::dispatch ( handler_type handler)
inline

尽可能在当前线程同步执行 handler

参数
handler要执行的 handler

若当前没有其他 handler 在执行(strand 未锁定),则在调用线程立即执行 handler。 否则降级为 post(),投递到队列等待串行执行。

在文件 strand.hpp93 行定义.

引用了 neforce::memory_order_acquire, neforce::memory_order_relaxed, neforce::memory_order_release, neforce::move() , 以及 post().

◆ get_executor()

io_context::executor neforce::strand::get_executor ( ) const
inlinenodiscardnoexcept

获取关联的 io_context 执行器

返回
io_context::executor 句柄

在文件 strand.hpp108 行定义.

◆ post()

void neforce::strand::post ( handler_type handler)
inline

投递 handler 到 strand 队列末尾

参数
handler要执行的 handler

handler 保证与 strand 中其他 handler 串行执行。

在文件 strand.hpp81 行定义.

引用了 neforce::move().

被这些函数引用 dispatch().


该类的文档由以下文件生成: