SObjectizer  5.8
Loading...
Searching...
No Matches
quotes.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \since
7 * v.5.5.8
8 *
9 * \file
10 * \brief A storage of quotes for priorities.
11 */
12
13#pragma once
14
15#include <so_5/priority.hpp>
16#include <so_5/exception.hpp>
17#include <so_5/ret_code.hpp>
18
19#include <algorithm>
20#include <iterator>
21
22#if defined(__clang__) && (__clang_major__ >= 16)
23#pragma clang diagnostic push
24#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
25#endif
26
27namespace so_5 {
28
29namespace disp {
30
31namespace prio_one_thread {
32
33namespace quoted_round_robin {
34
35/*!
36 * \since 5.5.8
37 * \brief A storage of quotes for priorities.
38 *
39 * A usage example:
40 \code
41 using namespace so_5::disp::prio_one_thread::quoted_round_robin;
42 quotes_t quotes{ 150 }; // Default value for all priorities.
43 quotes.set( so_5::prio::p7, 350 ); // New quote for p7.
44 quotes.set( so_5::prio::p6, 250 ); // New quote for p6.
45 // All other quotes will be 150.
46 ...
47 auto disp = make_dispatcher( env, quotes );
48 \endcode
49
50 Another example:
51 \code
52 using namespace so_5::disp::prio_one_thread::quoted_round_robin;
53 auto disp = make_dispatcher( env,
54 quotes_t{ 150 } // Default value for all priorites.
55 .set( so_5::prio::p7, 350 ) // New quote for p7.
56 .set( so_5::prio::p6, 250 ) // New quote for p6
57 );
58 \endcode
59
60 * \attention Value of 0 is illegal. An exception will be throw on
61 * attempt of setting 0 as a quote value.
62 */
64 {
65 public :
66 //! Initializing constructor sets the default value for
67 //! every priority.
68 quotes_t( std::size_t default_value )
69 {
70 ensure_quote_not_zero( default_value );
71 std::fill( std::begin(m_quotes), std::end(m_quotes), default_value );
72 }
73
74 //! Set a new quote for a priority.
75 quotes_t &
77 //! Priority to which a new quote to be set.
78 priority_t prio,
79 //! Quote value.
80 std::size_t quote )
81 {
82 ensure_quote_not_zero( quote );
83 m_quotes[ to_size_t( prio ) ] = quote;
84 return *this;
85 }
86
87 //! Get the quote for a priority.
88 size_t
89 query( priority_t prio ) const
90 {
91 return m_quotes[ to_size_t( prio ) ];
92 }
93
94 private :
95 //! Quotes for every priority.
97
98 static void
99 ensure_quote_not_zero( std::size_t value )
100 {
101 if( !value )
102 SO_5_THROW_EXCEPTION( rc_priority_quote_illegal_value,
103 "quote for a priority cannot be zero" );
104 }
105 };
106
107} /* namespace quoted_round_robin */
108
109} /* namespace prio_one_thread */
110
111} /* namespace disp */
112
113} /* namespace so_5 */
114
115#if defined(__clang__) && (__clang_major__ >= 16)
116#pragma clang diagnostic pop
117#endif
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.
size_t query(priority_t prio) const
Get the quote for a priority.
Definition quotes.hpp:89
quotes_t & set(priority_t prio, std::size_t quote)
Set a new quote for a priority.
Definition quotes.hpp:76
static void ensure_quote_not_zero(std::size_t value)
Definition quotes.hpp:99
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
#define SO_5_THROW_EXCEPTION(error_code, desc)
Definition exception.hpp:74
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