|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
线程池类 更多...
#include <thread_pool.hpp>
类 | |
| struct | periodic_task_state |
| 周期性任务状态 更多... | |
| struct | pool_statistics |
| 线程池统计信息 更多... | |
Public 类型 | |
| enum class | pool_mode : uint8_t { fixed , cached } |
| 线程池运行模式 更多... | |
| using | steal_strategy = local_queue::steal_strategy |
| 窃取策略类型别名 | |
| using | id_type = uint32_t |
| 线程ID类型别名 | |
| using | periodic_token = shared_ptr<periodic_task_state> |
| 周期性任务令牌 | |
| using | priority_type = task_info::priority_type |
| 优先级类型别名 | |
Public 成员函数 | |
| thread_pool () | |
| 默认构造函数 | |
| ~thread_pool () | |
| 析构函数 | |
| bool | set_mode (pool_mode mode) noexcept |
| 设置线程池模式 | |
| bool | set_steal_mode (steal_strategy strategy, uint32_t steal_batch=4) noexcept |
| 设置窃取策略 | |
| bool | set_task_threshhold (size_t threshhold) noexcept |
| 设置任务队列阈值 | |
| bool | set_thread_threshhold (size_t threshhold) noexcept |
| 设置线程数阈值 | |
| bool | running () const noexcept |
| 检查线程池是否正在运行 | |
| pool_mode | mode () const noexcept |
| 获取线程池模式 | |
| pool_statistics | statistics () const |
| 获取线程池统计信息 | |
| bool | start (size_t init_thread_size=3) |
| 启动线程池 | |
| pool_statistics | stop () |
| 停止线程池 | |
| template<typename Func, typename... Args> | |
| submit_result< invoke_result_t< Func, Args... > > | submit_task (priority_type priority, Func &&func, Args &&... args) |
| 提交任务 | |
| template<typename Func, typename... Args> | |
| submit_result< invoke_result_t< Func, Args... > > | submit_task (Func &&func, Args &&... args) |
| 提交任务(使用默认优先级0) | |
| template<typename Func, typename... Args> | |
| submit_result< invoke_result_t< Func, Args... > > | submit_after (int64_t delay_ms, priority_type priority, Func &&func, Args &&... args) |
| 提交延迟任务 | |
| template<typename Func, typename... Args> | |
| submit_result< invoke_result_t< Func, Args... > > | submit_after (int64_t delay_ms, Func &&func, Args &&... args) |
| 提交延迟任务(使用默认优先级0) | |
| template<typename Func, typename... Args> | |
| periodic_token | submit_every (int64_t interval_ms, priority_type priority, Func &&func, Args &&... args) |
| 提交周期性任务 | |
| template<typename Func, typename... Args> | |
| periodic_token | submit_every (int64_t interval_ms, Func &&func, Args &&... args) |
| 提交周期性任务(使用默认优先级0) | |
静态 Public 成员函数 | |
| static void | cancel_periodic_task (const periodic_token &token) |
| 取消周期性任务 | |
| template<typename... Types> | |
| static tuple< future_result_t< Types >... > | wait (future< Types > &&... futures) |
| 等待多个future完成 | |
静态 Public 属性 | |
| static constexpr size_t | task_max_threshhold = numeric_traits<int32_t>::max() |
| 最大任务队列阈值 | |
| static constexpr size_t | max_idle_seconds = 60 |
| 最大空闲秒数 | |
|
strong |
|
inlinestatic |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
noexcept |
|
noexcept |
设置窃取策略
| strategy | 窃取策略 |
| steal_batch | 批次大小 |
|
noexcept |
|
noexcept |
| bool thread_pool::start | ( | size_t | init_thread_size = 3 | ) |
启动线程池
| init_thread_size | 初始线程数,默认为3 |
|
nodiscard |
获取线程池统计信息
| pool_statistics thread_pool::stop | ( | ) |
停止线程池
|
inline |
提交延迟任务(使用默认优先级0)
| Func | 可调用对象类型 |
| Args | 参数类型 |
| delay_ms | 延迟时间(毫秒) |
| func | 可调用对象 |
| args | 参数 |
在文件 thread_pool.hpp 第 550 行定义.
引用了 forward() , 以及 submit_after().
| submit_result< invoke_result_t< Func, Args... > > thread_pool::submit_after | ( | int64_t | delay_ms, |
| priority_type | priority, | ||
| Func && | func, | ||
| Args &&... | args ) |
提交延迟任务
| Func | 可调用对象类型 |
| Args | 参数类型 |
| delay_ms | 延迟时间(毫秒) |
| priority | 任务优先级 |
| func | 可调用对象 |
| args | 参数 |
引用了 priority().
被这些函数引用 submit_after().
|
inline |
提交周期性任务(使用默认优先级0)
| Func | 可调用对象类型 |
| Args | 参数类型 |
| interval_ms | 执行间隔(毫秒) |
| func | 可调用对象 |
| args | 参数 |
在文件 thread_pool.hpp 第 578 行定义.
引用了 forward() , 以及 submit_every().
| periodic_token thread_pool::submit_every | ( | int64_t | interval_ms, |
| priority_type | priority, | ||
| Func && | func, | ||
| Args &&... | args ) |
提交周期性任务
| Func | 可调用对象类型 |
| Args | 参数类型 |
| interval_ms | 执行间隔(毫秒) |
| priority | 任务优先级 |
| func | 可调用对象 |
| args | 参数 |
引用了 priority().
被这些函数引用 submit_every().
|
inline |
提交任务(使用默认优先级0)
| Func | 可调用对象类型 |
| Args | 参数类型 |
| func | 可调用对象 |
| args | 参数 |
在文件 thread_pool.hpp 第 521 行定义.
引用了 forward() , 以及 submit_task().
| submit_result< invoke_result_t< Func, Args... > > thread_pool::submit_task | ( | priority_type | priority, |
| Func && | func, | ||
| Args &&... | args ) |
提交任务
| Func | 可调用对象类型 |
| Args | 参数类型 |
| priority | 任务优先级 |
| func | 可调用对象 |
| args | 参数 |
引用了 priority().
被这些函数引用 submit_task().
|
inlinestatic |
等待多个future完成
| Types | future结果类型 |
| futures | 要等待的future |
在文件 thread_pool.hpp 第 600 行定义.
引用了 get() , 以及 make_tuple().