SObjectizer  5.8
Loading...
Searching...
No Matches
prio_one_thread/strictly_ordered/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 * with priority support.
9 *
10 * \since v.5.5.8
11 */
12
13#pragma once
14
15#include <so_5/declspec.hpp>
16
17#include <so_5/disp_binder.hpp>
18
19#include <so_5/priority.hpp>
20
21#include <so_5/disp/mpsc_queue_traits/pub.hpp>
22
23#include <so_5/disp/reuse/work_thread_activity_tracking.hpp>
24#include <so_5/disp/reuse/work_thread_factory_params.hpp>
25
26#include <string>
27
28namespace so_5 {
29
30namespace disp {
31
32namespace prio_one_thread {
33
34namespace strictly_ordered {
35
36/*!
37 * \brief Alias for namespace with traits of event queue.
38 *
39 * \since v.5.5.10
40 */
41namespace queue_traits = so_5::disp::mpsc_queue_traits;
42
43//
44// disp_params_t
45//
46/*!
47 * \brief Parameters for a dispatcher.
48 *
49 * \since v.5.5.10
50 */
54 {
55 using activity_tracking_mixin_t = so_5::disp::reuse::
57 using thread_factory_mixin_t = so_5::disp::reuse::
59
60 public :
61 //! Default constructor.
62 disp_params_t() = default;
63
64 friend inline void
65 swap( disp_params_t & a, disp_params_t & b ) noexcept
66 {
67 swap(
68 static_cast< activity_tracking_mixin_t & >(a),
69 static_cast< activity_tracking_mixin_t & >(b) );
70
71 swap(
74
75 swap( a.m_queue_params, b.m_queue_params );
76 }
77
78 //! Setter for queue parameters.
81 {
82 m_queue_params = std::move(p);
83 return *this;
84 }
85
86 //! Tuner for queue parameters.
87 /*!
88 * Accepts lambda-function or functional object which tunes
89 * queue parameters.
90 \code
91 namespace prio_disp = so_5::disp::prio_one_thread::strictly_ordered;
92 auto disp = prio_disp::make_dispatcher( env,
93 "my_prio_disp",
94 prio_disp::disp_params_t{}.tune_queue_params(
95 []( prio_disp::queue_traits::queue_params_t & p ) {
96 p.lock_factory( prio_disp::queue_traits::simple_lock_factory() );
97 } ) );
98 \endcode
99 */
100 template< typename L >
103 {
105 return *this;
106 }
107
108 //! Getter for queue parameters.
109 const queue_traits::queue_params_t &
110 queue_params() const noexcept
111 {
112 return m_queue_params;
113 }
114
115 private :
116 //! Queue parameters.
118 };
119
120namespace impl
121{
122
124
125} /* namespace impl */
126
127//
128// dispatcher_handle_t
129//
130
131/*!
132 * \brief A handle for %prio_one_thread::strictly_ordered dispatcher.
133 *
134 * \since v.5.6.0
135 */
136class [[nodiscard]] dispatcher_handle_t
137 {
139
140 //! Binder for the dispatcher.
142
143 dispatcher_handle_t( disp_binder_shptr_t binder ) noexcept
144 : m_binder{ std::move(binder) }
145 {}
146
147 //! Is this handle empty?
148 bool
149 empty() const noexcept { return !m_binder; }
150
151 public :
152 dispatcher_handle_t() noexcept = default;
153
154 //! Get a binder for that dispatcher.
155 [[nodiscard]]
157 binder() const noexcept
158 {
159 return m_binder;
160 }
161
162 //! Is this handle empty?
163 operator bool() const noexcept { return empty(); }
164
165 //! Does this handle contain a reference to dispatcher?
166 bool
167 operator!() const noexcept { return !empty(); }
168
169 //! Drop the content of handle.
170 void
171 reset() noexcept { m_binder.reset(); }
172 };
173
174//
175// make_dispatcher
176//
177/*!
178 * \brief Create an instance of %strictly_ordered dispatcher.
179 *
180 * \par Usage sample
181\code
182auto common_thread_disp = so_5::disp::prio_one_thread::strictly_ordered::make_dispatcher(
183 env,
184 "request_processor",
185 so_5::disp::prio_one_thread::strictly_ordered::disp_params_t{}.tune_queue_params(
186 []( so_5::disp::prio_one_thread::strictly_ordered::queue_traits::queue_params_t & p ) {
187 p.lock_factory( so_5::disp::prio_one_thread::strictly_ordered::queue_traits::simple_lock_factory() );
188 } ) );
189auto coop = env.make_coop(
190 // The main dispatcher for that coop will be
191 // this instance of strictly_ordered dispatcher.
192 common_thread_disp.binder() );
193\endcode
194 *
195 * \since v.5.6.0
196 */
199 //! SObjectizer Environment to work in.
200 environment_t & env,
201 //! Value for creating names of data sources for
202 //! run-time monitoring.
203 const std::string_view data_sources_name_base,
204 //! Parameters for the dispatcher.
205 disp_params_t params );
206
207//
208// make_dispatcher
209//
210/*!
211 * \brief Create an instance of %strictly_ordered dispatcher.
212 *
213 * \par Usage sample
214\code
215auto common_thread_disp = so_5::disp::prio_one_thread::strictly_ordered::make_dispatcher(
216 env,
217 "request_processor" );
218auto coop = env.make_coop(
219 // The main dispatcher for that coop will be
220 // this instance of strictly_ordered dispatcher.
221 common_thread_disp.binder() );
222\endcode
223 *
224 * \since v.5.6.0
225 */
228 //! SObjectizer Environment to work in.
229 environment_t & env,
230 //! Value for creating names of data sources for
231 //! run-time monitoring.
232 const std::string_view data_sources_name_base )
233 {
234 return make_dispatcher( env, data_sources_name_base, disp_params_t{} );
235 }
236
237//
238// make_dispatcher
239//
240/*!
241 * \brief Create an instance of %strictly_ordered dispatcher.
242 *
243 * \par Usage sample
244\code
245auto common_thread_disp = so_5::disp::prio_one_thread::strictly_ordered::make_dispatcher( env );
246
247auto coop = env.make_coop(
248 // The main dispatcher for that coop will be
249 // private strictly_ordered dispatcher.
250 common_thread_disp.binder() );
251\endcode
252 *
253 * \since v.5.6.0
254 */
257 {
258 return make_dispatcher( env, std::string_view{} );
259 }
260
261} /* namespace strictly_ordered */
262
263} /* namespace prio_one_thread */
264
265} /* namespace disp */
266
267} /* namespace so_5 */
A base class for agents.
Definition agent.hpp:673
Container for storing parameters for MPSC queue.
const queue_traits::queue_params_t & queue_params() const noexcept
Getter for queue parameters.
disp_params_t & set_queue_params(queue_traits::queue_params_t p)
Setter for queue parameters.
disp_binder_shptr_t binder() const noexcept
Get a binder for that dispatcher.
bool operator!() const noexcept
Does this handle contain a reference to dispatcher?
void distribute_value_for_priority(const mbox_t &mbox, priority_t priority, std::size_t agents_count, std::size_t demands_count)
void distribute(const mbox_t &mbox) override
Send appropriate notification about the current value.
disp_data_source_t(const std::string_view name_base, outliving_reference_t< dispatcher_template_t > disp)
void unbind(agent_t &agent) noexcept override
Unbind agent from dispatcher.
dispatcher_template_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
void preallocate_resources(agent_t &) override
Allocate resources in dispatcher for new agent.
stats::auto_registered_source_holder_t< disp_data_source_t > m_data_source
Data source for run-time monitoring.
Mixin that holds optional work thread factory.
Interface for dispatcher binders.
SObjectizer Environment.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
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
Various stuff related to MPSC event queue implementation and tuning.
void send_thread_activity_stats(const so_5::mbox_t &, const stats::prefix_t &, so_5::disp::prio_one_thread::reuse::work_thread_no_activity_tracking_t< demand_queue_t > &)
Reusable code for dispatchers with one working thread for events of all priorities.
Implementation details for dispatcher which handles prioritized events in strict order.
Dispatcher which handles events in strict order (from highest priority to lowest).
dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base)
Create an instance of strictly_ordered 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 strictly_ordered dispatcher.
dispatcher_handle_t make_dispatcher(environment_t &env)
Create an instance of strictly_ordered dispatcher.
Dispatcher with one working thread for events of all priorities.
Reusable components for dispatchers.
Event dispatchers.
All stuff related to run-time monitoring and statistics.
Private part of message limit implementation.
Definition agent.cpp:33
priority_t
Definition of supported priorities.
Definition priority.hpp:28