2
3
6
7
8
9
10
12#include <so_5/disp/adv_thread_pool/pub.hpp>
14#include <so_5/disp/adv_thread_pool/impl/disp.hpp>
16#include <so_5/disp/reuse/make_actual_dispatcher.hpp>
18#include <so_5/ret_code.hpp>
20#include <so_5/disp_binder.hpp>
21#include <so_5/environment.hpp>
39
40
41
42
43
44
79
80
81
82
83
93 actual_dispatcher_iface_shptr_t disp,
103 m_disp->preallocate_resources_for_agent( agent, m_params );
108 agent_t & agent )
noexcept override
110 m_disp->undo_preallocation_for_agent( agent );
115 agent_t & agent )
noexcept override
117 auto queue = m_disp->query_resources_for_agent( agent );
118 agent.so_bind_to_dispatcher( *queue );
123 agent_t & agent )
noexcept override
125 m_disp->unbind_agent( agent );
133
134
135
136
137
138template<
typename Work_Thread >
139class actual_dispatcher_implementation_t
final
150 const std::string_view name_base,
157 params.thread_count(),
158 params.queue_params()
161 m_impl.start( env.get() );
166 m_impl.shutdown_then_wait();
172 return std::make_shared< actual_binder_t >(
173 this->shared_from_this(),
182 m_impl.preallocate_resources_for_agent( agent, params );
187 agent_t & agent )
noexcept override
189 m_impl.undo_preallocation_for_agent( agent );
195 return m_impl.query_resources_for_agent( agent );
201 m_impl.unbind_agent( agent );
212 make( actual_dispatcher_iface_shptr_t disp )
noexcept
214 return { std::move( disp ) };
224
225
226
227
228
229
233 if( !params.thread_count() )
234 params.thread_count( default_thread_pool_size() );
245 const std::string_view data_sources_name_base,
252 using dispatcher_no_activity_tracking_t =
253 impl::actual_dispatcher_implementation_t<
254 impl::work_thread_no_activity_tracking_t >;
256 using dispatcher_with_activity_tracking_t =
257 impl::actual_dispatcher_implementation_t<
258 impl::work_thread_with_activity_tracking_t >;
260 auto binder = so_5::disp::reuse::make_actual_dispatcher<
261 impl::actual_dispatcher_iface_t,
262 dispatcher_no_activity_tracking_t,
263 dispatcher_with_activity_tracking_t >(
264 outliving_mutable(env),
265 data_sources_name_base,
268 return impl::dispatcher_handle_maker_t::make( std::move(binder) );
Parameters for binding agents to adv_thread_pool dispatcher.
Alias for namespace with traits of event queue.
A handle for adv_thread_pool dispatcher.
void bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
const bind_params_t m_params
Binding parameters.
void unbind(agent_t &agent) noexcept override
Unbind agent from dispatcher.
actual_binder_t(actual_dispatcher_iface_shptr_t disp, bind_params_t params) noexcept
actual_dispatcher_iface_shptr_t m_disp
Dispatcher to be used.
void preallocate_resources(agent_t &agent) override
Allocate resources in dispatcher for new agent.
void undo_preallocation(agent_t &agent) noexcept override
Undo resources allocation.
An actual interface of thread-pool dispatcher.
virtual event_queue_t * query_resources_for_agent(agent_t &agent) noexcept=0
Get resources allocated for an agent.
virtual void undo_preallocation_for_agent(agent_t &agent) noexcept=0
Undo preallocation of resources for a new agent.
virtual void unbind_agent(agent_t &agent) noexcept=0
Unbind agent from the dispatcher.
virtual void preallocate_resources_for_agent(agent_t &agent, const bind_params_t ¶ms)=0
Preallocate all necessary resources for a new agent.
event_queue_t * query_resources_for_agent(agent_t &agent) noexcept override
Get resources allocated for an agent.
void unbind_agent(agent_t &agent) noexcept override
Unbind agent from the dispatcher.
disp_binder_shptr_t binder(bind_params_t params) override
void undo_preallocation_for_agent(agent_t &agent) noexcept override
Undo preallocation of resources for a new agent.
actual_dispatcher_implementation_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
dispatcher_template_t< Work_Thread > m_impl
Real dispatcher.
void preallocate_resources_for_agent(agent_t &agent, const bind_params_t ¶ms) override
Preallocate all necessary resources for a new agent.
~actual_dispatcher_implementation_t() noexcept override
The very basic interface of adv_thread_pool dispatcher.
static dispatcher_handle_t make(actual_dispatcher_iface_shptr_t disp) noexcept
Interface for dispatcher binders.
An interface of event queue for agent.
Helper class for indication of long-lived reference via its type.
void adjust_thread_count(disp_params_t ¶ms)
Sets the thread count to default value if used do not specify actual thread count.
Internal implementation details of advanced thread pool dispatcher.
Advanced thread pool dispatcher.
SO_5_FUNC dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base, disp_params_t params)
Create an instance of adv_thread_pool dispatcher.
Reusable components for dispatchers.
Private part of message limit implementation.