|
Botan 3.14.1
Crypto and TLS for C&
|
#include <thread_pool.h>
Public Member Functions | |
| Thread_Pool & | operator= (const Thread_Pool &)=delete |
| Thread_Pool & | operator= (Thread_Pool &&)=delete |
| void | queue_thunk (const std::function< void()> &work) |
| template<class F, class... Args> | |
| auto | run (F &&f, Args &&... args) -> Joining_Future< std::invoke_result_t< F, Args... > > |
| void | set_executor (std::shared_ptr< Work_Executor > executor) |
| void | shutdown () |
| Thread_Pool (const Thread_Pool &)=delete | |
| Thread_Pool (size_t pool_size=0) | |
| Thread_Pool (std::optional< size_t > pool_size) | |
| Thread_Pool (Thread_Pool &&)=delete | |
| size_t | worker_count () const |
| ~Thread_Pool () | |
Static Public Member Functions | |
| static Thread_Pool & | global_instance () |
Thread pool for computationally bound tasks
Callers queue fork-join work which is executed in arbitrary order. Do not use this interface for any kind of IO scheduling.
Definition at line 68 of file thread_pool.h.
|
explicit |
Initialize a thread pool with some number of threads
| pool_size | number of threads in the pool, if 0 then some default value is chosen. If the optional is nullopt then the thread pool is disabled; all work is executed immediately when queued. |
The threads are not started until work is first queued.
Definition at line 223 of file thread_pool.cpp.
Referenced by global_instance(), operator=(), operator=(), Thread_Pool(), Thread_Pool(), and Thread_Pool().
|
inlineexplicit |
Initialize a thread pool with some number of threads
| pool_size | number of threads in the pool, if 0 then some default value is chosen. |
Definition at line 91 of file thread_pool.h.
References Thread_Pool().
|
inline |
|
delete |
References Thread_Pool().
|
delete |
References Thread_Pool().
|
static |
Return an instance to a shared thread pool
Definition at line 213 of file thread_pool.cpp.
References Thread_Pool().
Referenced by Botan::Hash_Engine::create_or_null(), and Botan::Work_Executor::set_global().
|
delete |
References Thread_Pool().
|
delete |
References queue_thunk(), and Thread_Pool().
| void Botan::Thread_Pool::queue_thunk | ( | const std::function< void()> & | work | ) |
Definition at line 273 of file thread_pool.cpp.
References Botan::lock().
Referenced by operator=(), and run().
|
inline |
Queue fork-join work which will be executed in arbitrary order
Definition at line 137 of file thread_pool.h.
References queue_thunk().
| void Botan::Thread_Pool::set_executor | ( | std::shared_ptr< Work_Executor > | executor | ) |
Install an executor which runs queued work in place of the pool's threads
May be called at most once; the executor then remains in use for the lifetime of the pool. Any threads already started finish their queued work and exit.
Throws Invalid_State if an executor is already set, or if called from within work run by this pool.
Definition at line 233 of file thread_pool.cpp.
References BOTAN_ARG_CHECK, and Botan::lock().
Referenced by Botan::Work_Executor::set_global().
| void Botan::Thread_Pool::shutdown | ( | ) |
Definition at line 263 of file thread_pool.cpp.
References Botan::lock().
Referenced by ~Thread_Pool().
| size_t Botan::Thread_Pool::worker_count | ( | ) | const |
Return the number of threads available to run queued work
With an executor installed this is the max_concurrency it reported when it was installed. Otherwise it is the number of threads in the pool, where zero means the pool is disabled and all work runs in the calling thread. Returns zero once the pool has shut down.
Definition at line 228 of file thread_pool.cpp.
References Botan::lock().