Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::thread_pool Class Reference

A basic thread pool implementation for usage as a dispatcher. More...

#include <asyncpp/thread_pool.h>

Inheritance diagram for asyncpp::thread_pool:
[legend]

Public Member Functions

 thread_pool (size_t initial_size=std::thread::hardware_concurrency())
 Construct a new thread pool.
 
 thread_pool (const thread_pool &)=delete
 
thread_pooloperator= (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.
 

Additional Inherited Members

- Static Public Member Functions inherited from asyncpp::dispatcher
static dispatchercurrent () noexcept
 
- Static Protected Member Functions inherited from asyncpp::dispatcher
static dispatchercurrent (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.
 

Detailed Description

A basic thread pool implementation for usage as a dispatcher.

Constructor & Destructor Documentation

◆ thread_pool()

asyncpp::thread_pool::thread_pool ( size_t initial_size = std::thread::hardware_concurrency())
inlineexplicit

Construct a new thread pool.

Parameters
initial_sizeThe initial number of threads to spawn

Member Function Documentation

◆ push()

void asyncpp::thread_pool::push ( std::function< void()> cbfn)
inlineoverridevirtual

Push a callback into the pool.

Parameters
fnThe 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_sizeThe 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: