14#include <boost/asio/executor_work_guard.hpp>
15#include <boost/asio/io_context.hpp>
16#include <boost/asio/post.hpp>
43 typename ResultT =
typename std::invoke_result_t<
FunctorT()>>
45 auto task = std::packaged_task<ResultT()>(std::forward<FunctorT>(functor));
46 auto future = task.get_future();
60 AsyncRun(std::thread::hardware_concurrency());
89 boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
_work_to_do;
Inherit (privately) to suppress copy/move construction and assignment.
void CreateThreads(size_t count, F functor)
A thread pool based on Boost.Asio's io context.
void Stop()
Stop the ThreadPool and join all its threads.
void AsyncRun()
Launch threads to run tasks asynchronously.
boost::asio::executor_work_guard< boost::asio::io_context::executor_type > _work_to_do
void AsyncRun(size_t worker_threads)
Launch threads to run tasks asynchronously.
~ThreadPool()
Stops the ThreadPool and joins all its threads.
void RunFor(time_duration duration)
Run tasks in this thread for an specific duration.
void Run()
Run tasks in this thread.
boost::asio::io_context _io_context
auto & io_context()
Return the underlying io_context.
std::future< ResultT > Post(FunctorT &&functor)
Post a task to the pool.
Positive time duration up to milliseconds resolution.
constexpr auto to_chrono() const
This file contains definitions of common data structures used in traffic manager.
auto MoveHandler(FunctorT &&func)
Hack to trick asio into accepting move-only handlers, if the handler were actually copied it would re...