A basic thread pool implementation for usage as a dispatcher.
More...
#include <asyncpp/thread_pool.h>
|
| thread_pool (size_t initial_size=std::thread::hardware_concurrency()) |
| Construct a new thread pool.
|
|
| thread_pool (const thread_pool &)=delete |
|
thread_pool & | operator= (const thread_pool &)=delete |
|
void | push (std::function< void()> cbfn) override |
| Push a callback into the pool.
|
|
void | resize (size_t target_size) |
| Update the number of threads currently running.
|
|
size_t | size () const noexcept |
| Get the current number of threads.
|
|
|
static dispatcher * | current () noexcept |
|
static dispatcher * | current (dispatcher *disp) |
| Set the current dispatcher for this thread and reurns the current one. Implementers of dispatchers can use this to give convenient access to the current dispatcher, for example for yielding. A dispatcher usually calls this function once at the start of an event loop, before calling any callbacks and persists the return value. It then calls it again after calling all callbacks and restores the previously persisted value. This allows invoking a dispatcher loop from within another dispatcher. The end call is optional if the implementation can guarantee that the thread will terminate afterwards.
|
|
A basic thread pool implementation for usage as a dispatcher.
◆ thread_pool()
asyncpp::thread_pool::thread_pool |
( |
size_t | initial_size = std::thread::hardware_concurrency() | ) |
|
|
inlineexplicit |
Construct a new thread pool.
- Parameters
-
initial_size | The initial number of threads to spawn |
◆ push()
void asyncpp::thread_pool::push |
( |
std::function< void()> | cbfn | ) |
|
|
inlineoverridevirtual |
Push a callback into the pool.
- Parameters
-
fn | The callback to execute on the pool |
Implements asyncpp::dispatcher.
◆ resize()
void asyncpp::thread_pool::resize |
( |
size_t | target_size | ) |
|
|
inline |
Update the number of threads currently running.
- Parameters
-
target_size | The new number of threads |
◆ size()
size_t asyncpp::thread_pool::size |
( |
| ) |
const |
|
inlinenoexcept |
Get the current number of threads.
- Returns
- size_t Number of active threads
The documentation for this class was generated from the following file: