Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::named_thread_pool Class Reference

#include <thread_utils.hpp>

Public Member Functions

 named_thread_pool (std::string name_prefix, size_t num_threads)
 
 ~named_thread_pool ()
 
boost::asio::io_context & get_executor ()
 
void stop ()
 

Detailed Description

Wrapper class for boost asio thread pool and io_context run. Also names threads so that tools like htop can see thread name.

Definition at line 16 of file thread_utils.hpp.

Constructor & Destructor Documentation

◆ named_thread_pool()

sysio::chain::named_thread_pool::named_thread_pool ( std::string name_prefix,
size_t num_threads )

Definition at line 10 of file thread_utils.cpp.

11: _thread_pool( num_threads )
12, _ioc( num_threads )
13{
14 _ioc_work.emplace( boost::asio::make_work_guard( _ioc ) );
15 for( size_t i = 0; i < num_threads; ++i ) {
16 boost::asio::post( _thread_pool, [&ioc = _ioc, name_prefix, i]() {
17 std::string tn = name_prefix + "-" + std::to_string( i );
19 ioc.run();
20 } );
21 }
22}
void set_os_thread_name(const string &name)
Here is the call graph for this function:

◆ ~named_thread_pool()

sysio::chain::named_thread_pool::~named_thread_pool ( )

Definition at line 24 of file thread_utils.cpp.

24 {
25 stop();
26}
Here is the call graph for this function:

Member Function Documentation

◆ get_executor()

boost::asio::io_context & sysio::chain::named_thread_pool::get_executor ( )
inline

Definition at line 25 of file thread_utils.hpp.

25{ return _ioc; }
Here is the caller graph for this function:

◆ stop()

void sysio::chain::named_thread_pool::stop ( )

Definition at line 28 of file thread_utils.cpp.

28 {
29 _ioc_work.reset();
30 _ioc.stop();
31 _thread_pool.join();
32 _thread_pool.stop();
33}
Here is the caller graph for this function:

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