2
3
6
7
8
9
10
11
12
14#include <so_5/disp/prio_dedicated_threads/one_per_prio/pub.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/stats/repository.hpp>
23#include <so_5/stats/messages.hpp>
24#include <so_5/stats/std_names.hpp>
26#include <so_5/send_functions.hpp>
28#include <so_5/details/invoke_noexcept_code.hpp>
57 const so_5::mbox_t & mbox,
75
76
77
78
79
80
81template<
typename Work_Thread >
87 const std::string_view name_base,
92 outliving_mutable(*
this)
124 agent_t & agent )
noexcept override
136 agent_t & agent )
noexcept override
144 friend class disp_data_source_t;
147
148
149
150
151
152 class disp_data_source_t
final :
public stats::
source_t
162 const std::string_view name_base,
175 std::size_t agents_count = 0;
180 auto agents = disp.m_agents_per_priority[
183 agents_count += agents;
204 std::size_t agents_count,
207 std::ostringstream ss;
216 wt.demands_count() );
224 send_thread_activity_stats( mbox, prefix, wt );
233 std::vector< std::unique_ptr< Work_Thread > >
m_threads;
249 auto t = std::make_unique< Work_Thread >(
251 std::move(lock_factory) );
269 fill( begin(started_threads), end(started_threads),
nullptr );
271 do_with_rollback_on_exception( [&] {
275 std::memory_order_release );
281 started_threads[ i ] =
m_threads[ i ].get();
285 invoke_noexcept_code( [&] {
287 for(
auto t : started_threads )
308 make( disp_binder_shptr_t binder )
noexcept
310 return { std::move( binder )
};
322 const std::string_view data_sources_name_base,
327 using dispatcher_no_activity_tracking_t =
328 impl::dispatcher_template_t<
331 using dispatcher_with_activity_tracking_t =
332 impl::dispatcher_template_t<
333 work_thread::work_thread_with_activity_tracking_t >;
337 dispatcher_no_activity_tracking_t
,
338 dispatcher_with_activity_tracking_t
>(
340 data_sources_name_base
,
priority_t so_priority() const noexcept
Get the priority of the agent.
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 prio_dedicated_threads::one_per_prio dispatcher.
dispatcher_handle_t(disp_binder_shptr_t binder) noexcept
static dispatcher_handle_t make(disp_binder_shptr_t binder) noexcept
stats::prefix_t m_base_prefix
Basic prefix for data sources.
void distribute(const mbox_t &mbox) override
Send appropriate notification about the current value.
outliving_reference_t< dispatcher_template_t > m_dispatcher
Dispatcher to work with.
disp_data_source_t(const std::string_view name_base, outliving_reference_t< dispatcher_template_t > disp)
void distribute_value_for_work_thread(const mbox_t &mbox, priority_t priority, std::size_t agents_count, Work_Thread &wt)
void launch_work_threads()
Start all working threads.
stats::auto_registered_source_holder_t< disp_data_source_t > m_data_source
Data source for run-time monitoring.
std::vector< std::unique_ptr< Work_Thread > > m_threads
Working threads for every priority.
dispatcher_template_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
std::array< std::atomic< std::size_t >, so_5::prio::total_priorities_count > m_agents_per_priority
Counters for agent count for every priority.
void allocate_work_threads(environment_t &env, const disp_params_t ¶ms)
Allocate work threads for dispatcher.
void undo_preallocation(agent_t &) noexcept override
Undo resources allocation.
void bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
void preallocate_resources(agent_t &) override
Allocate resources in dispatcher for new agent.
void unbind(agent_t &agent) noexcept override
Unbind agent from dispatcher.
~dispatcher_template_t() noexcept override
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.
constexpr const char * c_str() const noexcept
Access to prefix value.
prefix_t(const std::string &value) noexcept(noexcept(value.c_str()))
Initializing constructor.
An interface of data source.
Some reusable and low-level classes/functions which can be used in public header files.
void send_thread_activity_stats(const so_5::mbox_t &, const stats::prefix_t &, work_thread::work_thread_no_activity_tracking_t &)
void send_thread_activity_stats(const so_5::mbox_t &mbox, const stats::prefix_t &prefix, work_thread::work_thread_with_activity_tracking_t &wt)
Implementation details for dispatcher with one thread per priority.
Dispatcher which creates exactly one thread per priority.
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_per_prio dispatcher.
Dispatchers with dedicated threads for every priority.
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...
Helpers for working with priorities.
const unsigned int total_priorities_count
Total count of priorities.
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.
std::size_t to_size_t(priority_t priority)
Helper function for conversion from priority to size_t.
priority_t
Definition of supported priorities.
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.
A message with value of some quantity.
Information about one work thread activity.