2
3
5#include <so_5/disp/one_thread/pub.hpp>
7#include <so_5/environment.hpp>
8#include <so_5/send_functions.hpp>
10#include <so_5/stats/repository.hpp>
11#include <so_5/stats/messages.hpp>
12#include <so_5/stats/std_names.hpp>
14#include <so_5/stats/impl/activity_tracking.hpp>
16#include <so_5/disp/reuse/work_thread/work_thread.hpp>
18#include <so_5/disp/reuse/actual_work_thread_factory_to_use.hpp>
19#include <so_5/disp/reuse/data_source_prefix_helpers.hpp>
20#include <so_5/disp/reuse/make_actual_dispatcher.hpp>
22#include <so_5/details/rollback_on_exception.hpp>
44template<
typename Work_Thread >
59 Work_Thread & work_thread,
60 std::atomic< std::size_t > & agents_bound )
69 const common_data_t< work_thread::work_thread_no_activity_tracking_t > & )
75 const common_data_t< work_thread::work_thread_with_activity_tracking_t > & data )
88
89
90template<
typename Work_Thread >
91class data_source_t
final
96 using actual_work_thread_type_t = Work_Thread;
99 actual_work_thread_type_t & work_thread,
100 std::atomic< std::size_t > & agents_bound,
101 const std::string_view name_base,
102 const void * pointer_to_disp )
104 work_thread, agents_bound }
114 this->m_work_thread_prefix = make_disp_working_thread_prefix(
126 this->m_agents_bound.load( std::memory_order_acquire ) );
130 this->m_work_thread_prefix,
132 this->m_work_thread.demands_count() );
143
144
145
146
147
148
149
150
151
152
153template<
typename Work_Thread >
159 const std::string_view name_base,
197 agent_t & agent )
noexcept override
215
216
217
218
219
223
224
225
226
227
239 make( disp_binder_shptr_t binder )
noexcept
241 return { std::move( binder )
};
253 const std::string_view data_sources_name_base,
258 using dispatcher_no_activity_tracking_t =
259 impl::actual_dispatcher_t<
262 using dispatcher_with_activity_tracking_t =
263 impl::actual_dispatcher_t<
264 work_thread::work_thread_with_activity_tracking_t >;
268 dispatcher_no_activity_tracking_t
,
269 dispatcher_with_activity_tracking_t
>(
271 data_sources_name_base
,
void so_bind_to_dispatcher(event_queue_t &queue) noexcept
Binding agent to the dispatcher.
const lock_factory_t & lock_factory() const
Getter for lock factory.
Alias for namespace with traits of event queue.
const queue_traits::queue_params_t & queue_params() const
Getter for queue parameters.
A handle for one_thread dispatcher.
dispatcher_handle_t(disp_binder_shptr_t binder) noexcept
void preallocate_resources(agent_t &) override
Allocate resources in dispatcher for new agent.
virtual void bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
virtual void unbind(agent_t &) noexcept override
Unbind agent from dispatcher.
Work_Thread m_work_thread
Working thread for the dispatcher.
void undo_preallocation(agent_t &) noexcept override
Undo resources allocation.
stats::auto_registered_source_holder_t< data_source_t< Work_Thread > > m_data_source
Data source for run-time monitoring.
~actual_dispatcher_t() noexcept override
std::atomic< std::size_t > m_agents_bound
Count of agents bound to this dispatcher.
actual_dispatcher_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
data_source_t(actual_work_thread_type_t &work_thread, std::atomic< std::size_t > &agents_bound, const std::string_view name_base, const void *pointer_to_disp)
void distribute(const mbox_t &mbox) override
Send appropriate notification about the current value.
static dispatcher_handle_t make(disp_binder_shptr_t binder) noexcept
so_5::stats::work_thread_activity_stats_t take_activity_stats()
Get the activity stats.
so_5::current_thread_id_t thread_id() const
Get ID of work thread.
Interface for dispatcher binders.
stats::repository_t & stats_repository()
Access to repository of data sources for run-time monitoring.
Helper class for indication of long-lived reference via its type.
A holder for data-souce that should be automatically registered and deregistered in registry.
A type for storing prefix of data_source name.
An interface of data source.
void track_activity(const mbox_t &, const common_data_t< work_thread::work_thread_no_activity_tracking_t > &)
void track_activity(const mbox_t &mbox, const common_data_t< work_thread::work_thread_with_activity_tracking_t > &data)
Implementation details for dispatcher with single working thread.
Dispatcher with single working thread.
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 one_thread dispatcher.
Implemetation details of dispatcher's working thread.
Reusable components for dispatchers.
work_thread_holder_t acquire_work_thread(const work_thread_factory_mixin_t< Params > ¶ms, environment_t &env)
Helper function for acquiring a new worker thread from an appropriate work thread factory.
so_5::stats::prefix_t make_disp_prefix(const std::string_view disp_type, const std::string_view data_sources_name_base, const void *disp_this_pointer)
Create basic prefix for dispatcher data source names.
std::unique_ptr< Disp_Iface_Type > make_actual_dispatcher(outliving_reference_t< environment_t > env, const std::string_view name_base, Disp_Params_Type disp_params, Args &&...args)
Helper function for creation of dispatcher instance with respect to work thread activity tracking fla...
Declarations of messages used by run-time monitoring and statistics.
Predefined suffixes of data-sources.
SO_5_FUNC suffix_t agent_count()
Suffix for data source with count of agents bound to some entity.
SO_5_FUNC suffix_t work_thread_queue_size()
Suffix for data source with count of demands in a working thread event queue.
SO_5_FUNC suffix_t work_thread_activity()
Suffix for data source with work thread activity statistics.
All stuff related to run-time monitoring and statistics.
Private part of message limit implementation.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
outliving_reference_t< T > outliving_mutable(T &r)
Make outliving_reference wrapper for mutable reference.
stats::prefix_t m_work_thread_prefix
Prefix for working thread-related data.
Work_Thread & m_work_thread
Working thread of the dispatcher.
common_data_t(Work_Thread &work_thread, std::atomic< std::size_t > &agents_bound)
stats::prefix_t m_base_prefix
Prefix for dispatcher-related data.
std::atomic< std::size_t > & m_agents_bound
Count of agents bound to the dispatcher.
A message with value of some quantity.
Information about one work thread activity.