SObjectizer  5.8
Loading...
Searching...
No Matches
prio_one_thread/quoted_round_robin/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 (quoted round robin policy).
9 *
10 * \since
11 * v.5.5.8
12 */
13
14#pragma once
15
16#include <so_5/declspec.hpp>
17
18#include <so_5/disp_binder.hpp>
19
20#include <so_5/priority.hpp>
21
22#include <so_5/disp/prio_one_thread/quoted_round_robin/quotes.hpp>
23
24#include <so_5/disp/mpsc_queue_traits/pub.hpp>
25
26#include <so_5/disp/reuse/work_thread_activity_tracking.hpp>
27#include <so_5/disp/reuse/work_thread_factory_params.hpp>
28
29#include <string>
30
31namespace so_5 {
32
33namespace disp {
34
35namespace prio_one_thread {
36
37namespace quoted_round_robin {
38
39/*!
40 * \brief Alias for namespace with traits of event queue.
41 *
42 * \since
43 * v.5.5.10
44 */
45namespace queue_traits = so_5::disp::mpsc_queue_traits;
46
47//
48// disp_params_t
49//
50/*!
51 * \brief Parameters for a dispatcher.
52 *
53 * \since
54 * v.5.5.10
55 */
59 {
60 using activity_tracking_mixin_t = so_5::disp::reuse::
62 using thread_factory_mixin_t = so_5::disp::reuse::
64
65 public :
66 //! Default constructor.
68
69 friend inline void
70 swap( disp_params_t & a, disp_params_t & b ) noexcept
71 {
72 swap(
73 static_cast< activity_tracking_mixin_t & >(a),
74 static_cast< activity_tracking_mixin_t & >(b) );
75
76 swap(
79
80 swap( a.m_queue_params, b.m_queue_params );
81 }
82
83 //! Setter for queue parameters.
86 {
87 m_queue_params = std::move(p);
88 return *this;
89 }
90
91 //! Tuner for queue parameters.
92 /*!
93 * Accepts lambda-function or functional object which tunes
94 * queue parameters.
95 \code
96 namespace prio_disp = so_5::disp::prio_one_thread::quoted_round_robin;
97 auto disp = prio_disp::make_dispatcher( env,
98 "my_prio_disp",
99 prio_disp::disp_params_t{}.tune_queue_params(
100 []( prio_disp::queue_traits::queue_params_t & p ) {
101 p.lock_factory( prio_disp::queue_traits::simple_lock_factory() );
102 } ) );
103 \endcode
104 */
105 template< typename L >
108 {
110 return *this;
111 }
112
113 //! Getter for queue parameters.
114 const queue_traits::queue_params_t &
116 {
117 return m_queue_params;
118 }
119
120 private :
121 //! Queue parameters.
123 };
124
125namespace impl
126{
127
129
130} /* namespace impl */
131
132//
133// dispatcher_handle_t
134//
135
136/*!
137 * \since
138 * v.5.6.0
139 *
140 * \brief A handle for %prio_one_thread::strictly_ordered dispatcher.
141 */
142class [[nodiscard]] dispatcher_handle_t
143 {
145
146 //! Binder for the dispatcher.
148
149 dispatcher_handle_t( disp_binder_shptr_t binder ) noexcept
150 : m_binder{ std::move(binder) }
151 {}
152
153 //! Is this handle empty?
154 bool
155 empty() const noexcept { return !m_binder; }
156
157 public :
158 dispatcher_handle_t() noexcept = default;
159
160 //! Get a binder for that dispatcher.
161 [[nodiscard]]
163 binder() const noexcept
164 {
165 return m_binder;
166 }
167
168 //! Is this handle empty?
169 operator bool() const noexcept { return empty(); }
170
171 //! Does this handle contain a reference to dispatcher?
172 bool
173 operator!() const noexcept { return !empty(); }
174
175 //! Drop the content of handle.
176 void
177 reset() noexcept { m_binder.reset(); }
178 };
179
180//
181// make_dispatcher
182//
183/*!
184 * \brief Create an instance of %quoted_round_robin dispatcher.
185 *
186 * \par Usage sample
187\code
188using namespace so_5::disp::prio_one_thread::quoted_round_robin;
189auto common_thread_disp = make_dispatcher(
190 env,
191 "request_processor",
192 quotes_t{ 75 }.set( so_5::prio::p7, 150 ).set( so_5::prio::p6, 125 ),
193 disp_params_t{}.tune_queue_params(
194 []( queue_traits::queue_params_t & p ) {
195 p.lock_factory( queue_traits::simple_lock_factory() );
196 } ) );
197auto coop = env.make_coop(
198 // The main dispatcher for that coop will be
199 // this instance of quoted_round_robin dispatcher.
200 common_thread_disp.binder() );
201\endcode
202 *
203 * \since
204 * v.5.6.0
205 */
208 //! SObjectizer Environment to work in.
209 environment_t & env,
210 //! Value for creating names of data sources for
211 //! run-time monitoring.
212 const std::string_view data_sources_name_base,
213 //! Quotes for every priority.
214 const quotes_t & quotes,
215 //! Parameters for the dispatcher.
216 disp_params_t params );
217
218//
219// make_dispatcher
220//
221/*!
222 * \brief Create an instance of %quoted_round_robin dispatcher.
223 *
224 * \par Usage sample
225\code
226using namespace so_5::disp::prio_one_thread::quoted_round_robin;
227auto common_thread_disp = make_dispatcher(
228 env,
229 "request_processor",
230 quotes_t{ 75 }.set( so_5::prio::p7, 150 ).set( so_5::prio::p6, 125 ) );
231auto coop = env.make_coop(
232 // The main dispatcher for that coop will be
233 // this instance of quoted_round_robin dispatcher.
234 common_thread_disp->binder() );
235\endcode
236 *
237 * \since
238 * v.5.6.0
239 */
242 //! SObjectizer Environment to work in.
243 environment_t & env,
244 //! Value for creating names of data sources for
245 //! run-time monitoring.
246 const std::string_view data_sources_name_base,
247 //! Quotes for every priority.
248 const quotes_t & quotes )
249 {
250 return make_dispatcher(
251 env,
252 data_sources_name_base,
253 quotes,
254 disp_params_t{} );
255 }
256
257//
258// make_dispatcher
259//
260/*!
261 * \brief Create an instance of %quoted_round_robin dispatcher.
262 *
263 * \par Usage sample
264\code
265using namespace so_5::disp::prio_one_thread::quoted_round_robin;
266auto common_thread_disp = make_dispatcher(
267 env,
268 quotes_t{ 75 }.set( so_5::prio::p7, 150 ).set( so_5::prio::p6, 125 ) );
269
270auto coop = env.make_coop(
271 // The main dispatcher for that coop will be
272 // this instance of quoted_round_robin dispatcher.
273 common_thread_disp.binder() );
274\endcode
275 *
276 * \since
277 * v.5.6.0
278 */
281 //! SObjectizer Environment to work in.
282 environment_t & env,
283 //! Quotes for every priority.
284 const quotes_t & quotes )
285 {
286 return make_dispatcher( env, std::string_view{}, quotes );
287 }
288
289} /* namespace quoted_round_robin */
290
291} /* namespace prio_one_thread */
292
293} /* namespace disp */
294
295} /* namespace so_5 */
A base class for agents.
Definition agent.hpp:673
Container for storing parameters for MPSC queue.
disp_params_t & set_queue_params(queue_traits::queue_params_t p)
Setter for queue parameters.
const queue_traits::queue_params_t & queue_params() const
Getter for queue parameters.
bool operator!() const noexcept
Does this handle contain a reference to dispatcher?
disp_binder_shptr_t binder() const noexcept
Get a binder for that dispatcher.
A demand queue for dispatcher with one common working thread and round-robin processing of prioritise...
disp_data_source_t(const std::string_view name_base, outliving_reference_t< dispatcher_template_t > disp)
void distribute_value_for_priority(const mbox_t &mbox, priority_t priority, std::size_t quote, std::size_t agents_count, std::size_t demands_count)
void distribute(const mbox_t &mbox) override
Send appropriate notification about the current value.
dispatcher_template_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params, const quotes_t &quotes)
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 > &)
Implementation details for dispatcher with round-robin policy of handling prioritized events.
Dispatcher which handles events of different priorities in round-robin maner.
dispatcher_handle_t make_dispatcher(environment_t &env, const quotes_t &quotes)
Create an instance of quoted_round_robin dispatcher.
dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base, const quotes_t &quotes)
Create an instance of quoted_round_robin dispatcher.
SO_5_FUNC dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base, const quotes_t &quotes, disp_params_t params)
Create an instance of quoted_round_robin dispatcher.
Reusable code for dispatchers with one working thread for events of all priorities.
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