faio
faio 公共 C++ 接口参考
载入中...
搜索中...
未找到
faio::runtime::current_thread_runtime类 参考

由调用线程驱动的独立运行时。 更多...

Public 类型

using scheduler_type = default_scheduler
 此实例接受的 task 使用的调度器类型。

Public 成员函数

 current_thread_runtime (faio::runtime::config config={})
 构造current_thread_runtime对象。
template<class T>
T block_on (task< T, scheduler_type > child)
 在普通线程驱动并等待一个异步任务组。
template<class T>
join_handle< T, scheduler_type > spawn (task< T, scheduler_type > child)
 立即提交一个独立并发任务。
template<class T>
void submit (task< T, scheduler_type > child)
 将任务提交给此实例。
template<class... Ts>
std::tuple< Ts... > wait_all (task< Ts, scheduler_type >... children)
 在此实例中等待一组任务全部完成。
template<class F>
auto spawn_blocking (F &&function)
 把同步函数提交到独立的有界阻塞线程池。
void request_stop () noexcept
 请求相关任务协作停止。
void shutdown (io::shutdown_policy policy=io::shutdown_policy::cancel_all)
 按指定策略关闭此实例。
void stop (io::shutdown_policy policy=io::shutdown_policy::drain)
 停止接纳并按策略排空此实例的工作。

详细描述

由调用线程驱动的独立运行时。

公共头文件
#include <faio/runtime/instance.hpp>

构造及析构函数说明

◆ current_thread_runtime()

faio::runtime::current_thread_runtime::current_thread_runtime ( faio::runtime::config config = {})
explicit

构造current_thread_runtime对象。

参数
config实例的运行时配置,驱动模式由所构造的类型决定。 默认值:{}。
返回值
构造函数不返回值。
注解
对象的复制、移动和资源所有权遵循类型说明。

成员函数说明

◆ block_on()

template<class T>
T faio::runtime::current_thread_runtime::block_on ( task< T, scheduler_type > child)

在普通线程驱动并等待一个异步任务组。

参数
child移动提交的惰性子任务;提交后调用方不再拥有它。
返回
返回任务的 T 结果;T 为 void 时无返回值,任务异常在调用线程重抛。
注解
禁止在运行时 worker 调用;协程内部使用 co_await。

◆ spawn()

template<class T>
join_handle< T, scheduler_type > faio::runtime::current_thread_runtime::spawn ( task< T, scheduler_type > child)

立即提交一个独立并发任务。

参数
child移动提交的惰性子任务;提交后调用方不再拥有它。
返回
返回 join_handle<T>,通过 co_await 或普通线程 get() 领取一次结果。
注解
任务移动到运行时;提交时不会等待任务完成。

◆ submit()

template<class T>
void faio::runtime::current_thread_runtime::submit ( task< T, scheduler_type > child)

将任务提交给此实例。

参数
child移动提交的惰性子任务;提交后调用方不再拥有它。
返回值
无返回值;由此实例驱动任务。

◆ wait_all()

template<class... Ts>
std::tuple< Ts... > faio::runtime::current_thread_runtime::wait_all ( task< Ts, scheduler_type >... children)

在此实例中等待一组任务全部完成。

参数
children移动传入的子任务参数包或任务集合,结果顺序对应输入顺序。
返回
按输入顺序返回结果 tuple。

◆ spawn_blocking()

template<class F>
auto faio::runtime::current_thread_runtime::spawn_blocking ( F && function)

把同步函数提交到独立的有界阻塞线程池。

参数
function执行所需工作的可调用对象;阻塞任务按值保存,非阻塞 I/O 回调不得阻塞。
返回
返回可等待的结果句柄;等待后取得函数结果或传播异常。
注解
等待不会阻塞协程 worker;任意同步函数不能被强制中断。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ request_stop()

void faio::runtime::current_thread_runtime::request_stop ( )
noexcept

请求相关任务协作停止。

返回值
无返回值;请求停止不表示任务已经退出。
注解
仍需等待结果或作用域收束,才能释放任务借用的资源。

◆ shutdown()

void faio::runtime::current_thread_runtime::shutdown ( io::shutdown_policy policy = io::shutdown_policy::cancel_all)

按指定策略关闭此实例。

参数
policy排空或先取消后排空。 默认值:io::shutdown_policy::cancel_all。
返回值
无返回值。默认 cancel_all。

◆ stop()

void faio::runtime::current_thread_runtime::stop ( io::shutdown_policy policy = io::shutdown_policy::drain)

停止接纳并按策略排空此实例的工作。

参数
policy排空或先取消后排空。 默认值:io::shutdown_policy::drain。
返回值
无返回值。默认 drain。