SObjectizer-5 Extra
Namespaces | Classes | Functions
so_5::extra::disp::asio_thread_pool Namespace Reference

Namespaces

 errors
 
 impl
 

Classes

struct  default_traits_t
 Default traits of asio_thread_pool dispatcher. More...
 
class  disp_params_t
 Parameters for asio_thread_pool dispatcher. More...
 
class  dispatcher_handle_t
 A handle for asio_thread_pool dispatcher. More...
 

Functions

std::size_t default_thread_pool_size ()
 A helper function for detecting default thread count for thread pool. More...
 
template<typename Traits = default_traits_t>
SO_5_NODISCARD dispatcher_handle_t make_dispatcher (environment_t &env, const std::string_view data_sources_name_base, disp_params_t disp_params)
 A function for creation an instance of asio_thread_pool dispatcher. More...
 

Function Documentation

◆ default_thread_pool_size()

std::size_t so_5::extra::disp::asio_thread_pool::default_thread_pool_size ( )
inline

A helper function for detecting default thread count for thread pool.

Since
v.1.0.2

Definition at line 1432 of file pub.hpp.

◆ make_dispatcher()

template<typename Traits = default_traits_t>
SO_5_NODISCARD dispatcher_handle_t so_5::extra::disp::asio_thread_pool::make_dispatcher ( environment_t &  env,
const std::string_view  data_sources_name_base,
disp_params_t  disp_params 
)
inline

A function for creation an instance of asio_thread_pool dispatcher.

Usage examples:

// Dispatcher which uses own Asio IoContext and default traits.
asio_tp::disp_params_t params;
params.use_own_io_context(); // Asio IoContext object will be created here.
// This object will be accessible later via
// private_dispatcher_t::io_context() method.
env,
"my_asio_tp",
std::move(disp_params) );
// Dispatcher which uses external Asio IoContext and default traits.
asio::io_context & io_svc = ...;
asio_tp::disp_params_t params;
params.use_external_io_context( io_svc );
env,
"my_asio_tp",
std::move(disp_params) );
// Dispatcher which uses own Asio IoContext and custom traits.
struct my_traits
{
using thread_type = my_custom_thread_type;
};
asio_tp::disp_params_t params;
params.use_own_io_context();
auto disp = asio_tp::make_dispatcher< my_traits >(
env,
"my_asio_tp",
std::move(disp_params) );
Requirements for traits type
Traits type must define a type which looks like:
struct traits
{
// Name of type to be used for thread class.
using thread_type = ...;
};
Requirements for custom thread type
By default std::thread is used as a class for working with threads. But user can specify its own custom thread type via Traits::thread_type parameter. A custom thread type must be a class which looks like:
class custom_thread_type {
public :
// Must provide this constructor.
// F -- is a type of functional object which can be converted
// into std::function<void()>.
template<typename F>
custom_thread_type(F && f) {...}
// Destructor must join thread if it is not joined yet.
~custom_thread_type() noexcept {...}
// The same semantic like std::thread::join.
void join() noexcept {...}
};
This class doesn't need to be DefaultConstructible, CopyConstructible, MoveConstructible, Copyable or Moveable.
Template Parameters
TraitsType with traits for a dispatcher. For the requirements for Traits type see the section "Requirements for traits type" above.
Since
v.1.0.2
Parameters
envSObjectizer Environment to work in.
data_sources_name_baseValue for creating names of data sources for run-time monitoring.
disp_paramsParameters for the dispatcher.
Examples:
async_op/time_limited/simple/main.cpp, async_op/time_unlimited/simple/main.cpp, disp/asio_thread_pool/hello_world/main.cpp, mboxes/collecting_mbox/advanced/main.cpp, mboxes/collecting_mbox/simple/main.cpp, mboxes/round_robin/advanced/main.cpp, and sync/simple/main.cpp.

Definition at line 1543 of file pub.hpp.