|
CARLA
|
A thread pool based on Boost.Asio's io context. More...
#include <ThreadPool.h>
Public Member Functions | |
| void | AsyncRun () |
| Launch threads to run tasks asynchronously. | |
| void | AsyncRun (size_t worker_threads) |
| Launch threads to run tasks asynchronously. | |
| auto & | io_context () |
| Return the underlying io_context. | |
| template<typename FunctorT, typename ResultT = typename std::invoke_result_t<FunctorT()>> | |
| std::future< ResultT > | Post (FunctorT &&functor) |
| Post a task to the pool. | |
| void | Run () |
| Run tasks in this thread. | |
| void | RunFor (time_duration duration) |
| Run tasks in this thread for an specific duration. | |
| void | Stop () |
| Stop the ThreadPool and join all its threads. | |
| ThreadPool () | |
| ~ThreadPool () | |
| Stops the ThreadPool and joins all its threads. | |
Static Public Member Functions | |
| static bool | IsPoolThread () |
| Whether the calling thread is a ThreadPool worker (it must not destroy its own pool). | |
Static Private Member Functions | |
| static bool & | IsPoolThreadFlag () |
Private Attributes | |
| boost::asio::io_context | _io_context |
| boost::asio::executor_work_guard< boost::asio::io_context::executor_type > | _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 25 of file ThreadPool.h.
|
inline |
Definition at line 28 of file ThreadPool.h.
References _io_context, and _work_to_do.
|
inline |
Stops the ThreadPool and joins all its threads.
Definition at line 31 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 67 of file ThreadPool.h.
References AsyncRun().
|
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 54 of file ThreadPool.h.
References _workers, carla::ThreadGroup::CreateThreads(), IsPoolThreadFlag(), and Run().
Referenced by carla::multigpu::Router::AsyncRun(), carla::multigpu::Secondary::AsyncRun(), carla::streaming::Client::AsyncRun(), carla::streaming::Server::AsyncRun(), and AsyncRun().
|
inline |
Return the underlying io_context.
Definition at line 36 of file ThreadPool.h.
References _io_context.
Referenced by carla::multigpu::Router::Router(), and carla::streaming::Client::Subscribe().
|
inlinestatic |
Whether the calling thread is a ThreadPool worker (it must not destroy its own pool).
Definition at line 62 of file ThreadPool.h.
References IsPoolThreadFlag().
Referenced by carla::client::detail::Simulator::Delete().
|
inlinestaticprivate |
Definition at line 95 of file ThreadPool.h.
Referenced by AsyncRun(), and IsPoolThread().
|
inline |
Post a task to the pool.
Definition at line 44 of file ThreadPool.h.
References _io_context, and carla::MoveHandler().
|
inline |
Run tasks in this thread.
Definition at line 74 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 82 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 87 of file ThreadPool.h.
References _io_context, _work_to_do, _workers, and carla::ThreadGroup::JoinAll().
Referenced by carla::multigpu::Router::Stop(), carla::multigpu::Secondary::Stop(), carla::streaming::Client::Stop(), carla::streaming::Client::~Client(), carla::multigpu::Secondary::~Secondary(), carla::streaming::Server::~Server(), and ~ThreadPool().
|
private |
Definition at line 100 of file ThreadPool.h.
Referenced by io_context(), Post(), Run(), RunFor(), Stop(), and ThreadPool().
|
private |
Definition at line 102 of file ThreadPool.h.
Referenced by Stop(), and ThreadPool().
|
private |
Definition at line 104 of file ThreadPool.h.
Referenced by AsyncRun(), and Stop().