TARAXA
taraxa::util::ThreadPool Class Reference

#include <thread_pool.hpp>

Collaboration diagram for taraxa::util::ThreadPool:

Classes

struct  Periodicity
 

Public Member Functions

 ThreadPool (size_t num_threads=std::thread::hardware_concurrency(), bool _start=true)
 
 ~ThreadPool ()
 
 ThreadPool (ThreadPool const &)=delete
 
ThreadPooloperator= (ThreadPool const &)=delete
 
 ThreadPool (ThreadPool &&)=delete
 
ThreadPooloperator= (ThreadPool &&)=delete
 
auto capacity () const
 
uint64_t num_pending_tasks () const
 
auto & unsafe_get_io_context ()
 
void start ()
 
bool is_running () const
 
void stop ()
 
void post (uint64_t do_in_ms, asio_callback action)
 
void post (uint64_t err, std::function< void()> action)
 
template<typename Action >
auto post (Action &&action)
 
void post_loop (Periodicity const &periodicity, std::function< void()> action)
 
 operator task_executor_t ()
 

Private Types

using asio_callback = std::function< void(boost::system::error_code const &)>
 

Private Attributes

boost::asio::io_context ioc_
 
boost::asio::executor_work_guard< decltype(ioc_)::executor_type > ioc_work_
 
std::vector< std::thread > threads_
 
std::atomic< uint64_t > num_pending_tasks_ = 0
 

Class Documentation

◆ taraxa::util::ThreadPool::Periodicity

struct taraxa::util::ThreadPool::Periodicity
Class Members
uint64_t delay_ms
uint64_t period_ms

Member Typedef Documentation

◆ asio_callback

using taraxa::util::ThreadPool::asio_callback = std::function<void(boost::system::error_code const &)>
private

Constructor & Destructor Documentation

◆ ThreadPool() [1/3]

taraxa::util::ThreadPool::ThreadPool ( size_t  num_threads = std::thread::hardware_concurrency(),
bool  _start = true 
)
explicit

◆ ~ThreadPool()

taraxa::util::ThreadPool::~ThreadPool ( )

◆ ThreadPool() [2/3]

taraxa::util::ThreadPool::ThreadPool ( ThreadPool const &  )
delete

◆ ThreadPool() [3/3]

taraxa::util::ThreadPool::ThreadPool ( ThreadPool &&  )
delete

Member Function Documentation

◆ capacity()

auto taraxa::util::ThreadPool::capacity ( ) const
inline

◆ is_running()

bool taraxa::util::ThreadPool::is_running ( ) const

◆ num_pending_tasks()

uint64_t taraxa::util::ThreadPool::num_pending_tasks ( ) const
inline

◆ operator task_executor_t()

taraxa::util::ThreadPool::operator task_executor_t ( )
inline

◆ operator=() [1/2]

ThreadPool& taraxa::util::ThreadPool::operator= ( ThreadPool &&  )
delete

◆ operator=() [2/2]

ThreadPool& taraxa::util::ThreadPool::operator= ( ThreadPool const &  )
delete

◆ post() [1/3]

template<typename Action >
auto taraxa::util::ThreadPool::post ( Action &&  action)
inline

◆ post() [2/3]

void taraxa::util::ThreadPool::post ( uint64_t  do_in_ms,
asio_callback  action 
)

◆ post() [3/3]

void taraxa::util::ThreadPool::post ( uint64_t  err,
std::function< void()>  action 
)

◆ post_loop()

void taraxa::util::ThreadPool::post_loop ( Periodicity const &  periodicity,
std::function< void()>  action 
)

◆ start()

void taraxa::util::ThreadPool::start ( )

◆ stop()

void taraxa::util::ThreadPool::stop ( )

◆ unsafe_get_io_context()

auto& taraxa::util::ThreadPool::unsafe_get_io_context ( )
inline

Member Data Documentation

◆ ioc_

boost::asio::io_context taraxa::util::ThreadPool::ioc_
private

◆ ioc_work_

boost::asio::executor_work_guard<decltype(ioc_)::executor_type> taraxa::util::ThreadPool::ioc_work_
private

◆ num_pending_tasks_

std::atomic<uint64_t> taraxa::util::ThreadPool::num_pending_tasks_ = 0
private

◆ threads_

std::vector<std::thread> taraxa::util::ThreadPool::threads_
private

The documentation for this class was generated from the following files: