SObjectizer 5.8
Loading...
Searching...
No Matches
one_thread/pub.hpp
Go to the documentation of this file.
1/*
2 SObjectizer 5.
3*/
4
5/*!
6 \file
7 \brief Functions for creating and binding of the single thread dispatcher.
8*/
9
10#pragma once
11
12#include <so_5/declspec.hpp>
13
14#include <so_5/disp_binder.hpp>
15#include <so_5/nonempty_name.hpp>
16
17#include <so_5/disp/one_thread/params.hpp>
18
19#include <string_view>
20
21namespace so_5
22{
23
24namespace disp
25{
26
27namespace one_thread
28{
29
30namespace impl
31{
32
34
35} /* namespace impl */
36
37//
38// dispatcher_handle_t
39//
40
41/*!
42 * \since
43 * v.5.6.0
44 *
45 * \brief A handle for %one_thread dispatcher.
46 */
47class [[nodiscard]] dispatcher_handle_t
48 {
50
51 //! Binder for the dispatcher.
52 disp_binder_shptr_t m_binder;
53
54 dispatcher_handle_t( disp_binder_shptr_t binder ) noexcept
55 : m_binder{ std::move(binder) }
56 {}
57
58 //! Is this handle empty?
59 bool
60 empty() const noexcept { return !m_binder; }
61
62 public :
63 dispatcher_handle_t() noexcept = default;
64
65 //! Get a binder for that dispatcher.
66 [[nodiscard]]
67 disp_binder_shptr_t
68 binder() const noexcept
69 {
70 return m_binder;
71 }
72
73 //! Is this handle empty?
74 operator bool() const noexcept { return empty(); }
75
76 //! Does this handle contain a reference to dispatcher?
77 bool
78 operator!() const noexcept { return !empty(); }
79
80 //! Drop the content of handle.
81 void
82 reset() noexcept { m_binder.reset(); }
83 };
84
85//
86// make_dispatcher
87//
88
89/*!
90 * \brief Create an instance of %one_thread dispatcher.
91 *
92 * \par Usage sample
93\code
94auto one_thread_disp = so_5::disp::one_thread::make_dispatcher(
95 env,
96 "file_handler",
97 so_5::disp::one_thread::disp_params_t{}.tune_queue_params(
98 []( so_5::disp::one_thread::queue_traits::queue_params_t & p ) {
99 p.lock_factory( so_5::disp::one_thread::queue_traits::simple_lock_factory();
100 } ) );
101auto coop = env.make_coop(
102 // The main dispatcher for that coop will be
103 // this instance of one_thread dispatcher.
104 one_thread_disp.binder() );
105\endcode
106 *
107 * \since
108 * v.5.6.0
109 */
112 //! SObjectizer Environment to work in.
113 environment_t & env,
114 //! Value for creating names of data sources for
115 //! run-time monitoring.
116 const std::string_view data_sources_name_base,
117 //! Parameters for the dispatcher.
118 disp_params_t params );
119
120/*!
121 * \brief Create an instance of %one_thread dispatcher.
122 *
123 * \par Usage sample
124\code
125auto one_thread_disp = so_5::disp::one_thread::make_dispatcher(
126 env,
127 "file_handler" );
128auto coop = env.make_coop(
129 // The main dispatcher for that coop will be
130 // this instance of one_thread dispatcher.
131 one_thread_disp.binder() );
132\endcode
133 *
134 * \since
135 * v.5.6.0
136 */
139 //! SObjectizer Environment to work in.
140 environment_t & env,
141 //! Value for creating names of data sources for
142 //! run-time monitoring.
143 const std::string_view data_sources_name_base )
144 {
145 return make_dispatcher( env, data_sources_name_base, disp_params_t{} );
146 }
147
148/*!
149 * \brief Create an instance of %one_thread dispatcher.
150 *
151 * \par Usage sample
152\code
153auto one_thread_disp = so_5::disp::one_thread::make_dispatcher( env );
154
155auto coop = env.make_coop(
156 // The main dispatcher for that coop will be
157 // this instance of one_thread dispatcher.
158 one_thread_disp.binder() );
159\endcode
160 *
161 * \since
162 * v.5.6.0
163 */
166 {
167 return make_dispatcher( env, std::string_view{}, disp_params_t{} );
168 }
169
170} /* namespace one_thread */
171
172} /* namespace disp */
173
174} /* namespace so_5 */
A base class for agents.
Definition agent.hpp:673
void so_bind_to_dispatcher(event_queue_t &queue) noexcept
Binding agent to the dispatcher.
Definition agent.cpp:872
const lock_factory_t & lock_factory() const
Getter for lock factory.
Alias for namespace with traits of event queue.
disp_params_t()=default
Default constructor.
const queue_traits::queue_params_t & queue_params() const
Getter for queue parameters.
A handle for one_thread dispatcher.
operator bool() const noexcept
Is this handle empty?
bool operator!() const noexcept
Does this handle contain a reference to dispatcher?
disp_binder_shptr_t m_binder
Binder for the dispatcher.
disp_binder_shptr_t binder() const noexcept
Get a binder for that dispatcher.
void reset() noexcept
Drop the content of handle.
dispatcher_handle_t(disp_binder_shptr_t binder) noexcept
bool empty() const noexcept
Is this handle empty?
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.
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.
SObjectizer Environment.
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.
Definition outliving.hpp:98
T & get() const noexcept
A holder for data-souce that should be automatically registered and deregistered in registry.
A type for storing prefix of data_source name.
Definition prefix.hpp:32
An interface of data source.
#define SO_5_FUNC
Definition declspec.hpp:48
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.
dispatcher_handle_t make_dispatcher(environment_t &env)
Create an instance of one_thread dispatcher.
dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base)
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 > &params, 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...
Event dispatchers.
Declarations of messages used by run-time monitoring and statistics.
Definition messages.hpp:36
Predefined suffixes of data-sources.
Definition std_names.hpp:55
SO_5_FUNC suffix_t agent_count()
Suffix for data source with count of agents bound to some entity.
Definition std_names.cpp:66
SO_5_FUNC suffix_t work_thread_queue_size()
Suffix for data source with count of demands in a working thread event queue.
Definition std_names.cpp:78
SO_5_FUNC suffix_t work_thread_activity()
Suffix for data source with work thread activity statistics.
Definition std_names.cpp:84
All stuff related to run-time monitoring and statistics.
Private part of message limit implementation.
Definition agent.cpp:33
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.
Definition messages.hpp:60
Information about one work thread activity.
Definition messages.hpp:108