A thread pool based on Boost.Asio's io context. More...
#include <ThreadPool.h>
Public Member Functions | |
void | AsyncRun (size_t worker_threads) |
Launch threads to run tasks asynchronously. More... | |
void | AsyncRun () |
Launch threads to run tasks asynchronously. More... | |
auto & | io_context () |
Return the underlying io_context. More... | |
template<typename FunctorT , typename ResultT = typename std::result_of<FunctorT()>::type> | |
std::future< ResultT > | Post (FunctorT &&functor) |
Post a task to the pool. More... | |
void | Run () |
Run tasks in this thread. More... | |
void | RunFor (time_duration duration) |
Run tasks in this thread for an specific duration. More... | |
void | Stop () |
Stop the ThreadPool and join all its threads. More... | |
ThreadPool () | |
~ThreadPool () | |
Stops the ThreadPool and joins all its threads. More... | |
Private Attributes | |
boost::asio::io_context | _io_context |
boost::asio::io_context::work | _work_to_do |
ThreadGroup | _workers |
Additional Inherited Members | |
Private Member Functions inherited from carla::NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
NonCopyable (NonCopyable &&)=delete | |
NonCopyable & | operator= (const NonCopyable &)=delete |
NonCopyable & | operator= (NonCopyable &&)=delete |
A thread pool based on Boost.Asio's io context.
Definition at line 24 of file ThreadPool.h.
|
inline |
Definition at line 27 of file ThreadPool.h.
|
inline |
Stops the ThreadPool and joins all its threads.
Definition at line 30 of file ThreadPool.h.
References Stop().
|
inline |
Launch threads to run tasks asynchronously.
Launch specific number of threads if worker_threads is provided, otherwise use all available hardware concurrency.
Definition at line 51 of file ThreadPool.h.
References _workers, carla::ThreadGroup::CreateThreads(), and Run().
Referenced by carla::multigpu::Router::AsyncRun(), carla::streaming::Client::AsyncRun(), carla::multigpu::Secondary::AsyncRun(), carla::streaming::Server::AsyncRun(), and TEST().
|
inline |
Launch threads to run tasks asynchronously.
Launch specific number of threads if worker_threads is provided, otherwise use all available hardware concurrency.
Definition at line 56 of file ThreadPool.h.
|
inline |
Return the underlying io_context.
Definition at line 35 of file ThreadPool.h.
References _io_context.
Referenced by carla::multigpu::Router::Router(), and carla::streaming::Client::Subscribe().
|
inline |
Post a task to the pool.
Definition at line 41 of file ThreadPool.h.
References _io_context, and carla::MoveHandler().
Referenced by TEST().
|
inline |
Run tasks in this thread.
Definition at line 63 of file ThreadPool.h.
References _io_context.
Referenced by AsyncRun(), carla::streaming::Client::Run(), and carla::streaming::Server::Run().
|
inline |
Run tasks in this thread for an specific duration.
Definition at line 71 of file ThreadPool.h.
References _io_context, and carla::time_duration::to_chrono().
|
inline |
Stop the ThreadPool and join all its threads.
Definition at line 76 of file ThreadPool.h.
References _io_context, _workers, and carla::ThreadGroup::JoinAll().
Referenced by carla::multigpu::Router::Stop(), carla::streaming::Client::~Client(), carla::multigpu::Secondary::~Secondary(), carla::streaming::Server::~Server(), and ~ThreadPool().
|
private |
Definition at line 83 of file ThreadPool.h.
Referenced by io_context(), Post(), Run(), RunFor(), and Stop().
|
private |
Definition at line 85 of file ThreadPool.h.
|
private |
Definition at line 87 of file ThreadPool.h.
Referenced by AsyncRun(), and Stop().