SObjectizer 5.8
Loading...
Searching...
No Matches
nef_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 * that provides noexcept guarantee for scheduling evt_finish demand.
9 *
10 * \since v.5.8.0
11 */
12
13#pragma once
14
15#include <so_5/disp/nef_one_thread/params.hpp>
16
17#include <so_5/declspec.hpp>
18
19#include <so_5/disp_binder.hpp>
20
21#include <string>
22
23namespace so_5 {
24
25namespace disp {
26
27namespace nef_one_thread {
28
29namespace impl
30{
31
33
34} /* namespace impl */
35
36//
37// dispatcher_handle_t
38//
39
40/*!
41 * \brief A handle for %nef_one_thread dispatcher.
42 *
43 * \since v.5.8.0
44 */
45class [[nodiscard]] dispatcher_handle_t
46 {
48
49 //! Binder for the dispatcher.
50 disp_binder_shptr_t m_binder;
51
52 dispatcher_handle_t( disp_binder_shptr_t binder ) noexcept
53 : m_binder{ std::move(binder) }
54 {}
55
56 //! Is this handle empty?
57 bool
58 empty() const noexcept { return !m_binder; }
59
60 public :
61 dispatcher_handle_t() noexcept = default;
62
63 //! Get a binder for that dispatcher.
64 [[nodiscard]]
65 disp_binder_shptr_t
66 binder() const noexcept
67 {
68 return m_binder;
69 }
70
71 //! Is this handle empty?
72 operator bool() const noexcept { return empty(); }
73
74 //! Does this handle contain a reference to dispatcher?
75 bool
76 operator!() const noexcept { return !empty(); }
77
78 //! Drop the content of handle.
79 void
80 reset() noexcept { m_binder.reset(); }
81 };
82
83//
84// make_dispatcher
85//
86/*!
87 * \brief Create an instance of %nef_one_thread dispatcher.
88 *
89 * \par Usage sample
90\code
91auto my_disp = so_5::disp::nef_one_thread::make_dispatcher(
92 env,
93 "request_processor",
94 so_5::disp::nef_one_thread::disp_params_t{}.tune_queue_params(
95 []( so_5::disp::nef_one_thread::queue_traits::queue_params_t & p ) {
96 p.lock_factory( so_5::disp::nef_one_thread::queue_traits::simple_lock_factory() );
97 } ) );
98auto coop = env.make_coop(
99 // The main dispatcher for that coop will be
100 // this instance of nef_one_thread dispatcher.
101 my_disp.binder() );
102\endcode
103 *
104 * \since v.5.8.0
105 */
108 //! SObjectizer Environment to work in.
109 environment_t & env,
110 //! Value for creating names of data sources for
111 //! run-time monitoring.
112 const std::string_view data_sources_name_base,
113 //! Parameters for the dispatcher.
114 disp_params_t params );
115
116//
117// make_dispatcher
118//
119/*!
120 * \brief Create an instance of %nef_one_thread dispatcher.
121 *
122 * \par Usage sample
123\code
124auto my_disp = so_5::disp::nef_one_thread::make_dispatcher(
125 env,
126 "request_processor" );
127auto coop = env.make_coop(
128 // The main dispatcher for that coop will be
129 // this instance of nef_one_thread dispatcher.
130 my_disp.binder() );
131\endcode
132 *
133 * \since v.5.8.0
134 */
137 //! SObjectizer Environment to work in.
138 environment_t & env,
139 //! Value for creating names of data sources for
140 //! run-time monitoring.
141 const std::string_view data_sources_name_base )
142 {
143 return make_dispatcher( env, data_sources_name_base, disp_params_t{} );
144 }
145
146//
147// make_dispatcher
148//
149/*!
150 * \brief Create an instance of %nef_one_thread dispatcher.
151 *
152 * \par Usage sample
153\code
154auto my_disp = so_5::disp::nef_one_thread::make_dispatcher( env );
155
156auto coop = env.make_coop(
157 // The main dispatcher for that coop will be
158 // private nef_one_thread dispatcher.
159 my_disp.binder() );
160\endcode
161 *
162 * \since v.5.8.0
163 */
166 {
167 return make_dispatcher( env, std::string_view{} );
168 }
169
170} /* namespace nef_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
An analog of std::lock_guard for MPSC queue lock.
const lock_factory_t & lock_factory() const
Getter for lock factory.
An analog of std::unique_lock for MPSC queue lock.
Alias for namespace with traits of event queue.
const queue_traits::queue_params_t & queue_params() const noexcept
Getter for queue parameters.
disp_params_t()=default
Default constructor.
A handle for nef_one_thread dispatcher.
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.
disp_binder_shptr_t m_binder
Binder for the dispatcher.
bool empty() const noexcept
Is this handle empty?
operator bool() const noexcept
Is this handle empty?
void reset() noexcept
Drop the content of handle.
dispatcher_handle_t(disp_binder_shptr_t binder) noexcept
agent_queue_t(const agent_queue_t &)=delete
void push_evt_finish(execution_demand_t demand) noexcept override
Enqueue a demand for evt_finish event.
void push_evt_start(execution_demand_t demand) override
Enqueue a demand for evt_start event.
std::reference_wrapper< demand_queue_t > m_dest_queue
void push(execution_demand_t demand) override
Enqueue new event to the queue.
agent_queue_t & operator=(const agent_queue_t &)=delete
agent_queue_t(demand_queue_t &dest_queue, demand_unique_ptr_t evt_start_demand, demand_unique_ptr_t evt_finish_demand)
agent_queue_t & operator=(agent_queue_t &&o)=delete
demand_unique_ptr_t remove_head() noexcept
Helper method for deleting queue's head object.
std::size_t size() const
Get the current size of the queue.
std::atomic< std::size_t > m_size
Current size of the queue.
demand_queue_t(queue_traits::lock_unique_ptr_t lock)
Initializing constructor.
queue_traits::lock_unique_ptr_t m_lock
Queue lock.
static dispatcher_handle_t make(disp_binder_shptr_t binder) noexcept
outliving_reference_t< dispatcher_template_t > m_dispatcher
Dispatcher to work with.
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 bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
std::mutex m_agent_map_lock
Lock for agent_map protection.
void undo_preallocation(agent_t &agent) noexcept override
Undo resources allocation.
Work_Thread m_work_thread
Worker thread for the dispatcher.
void preallocate_resources(agent_t &agent) 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.
agent_map_t m_agents
Agents for those resources are allocated by the dispatcher.
dispatcher_template_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
void unbind(agent_t &agent) noexcept override
Unbind agent from dispatcher.
A part of implementation of work thread without activity tracking.
no_activity_tracking_impl_t(queue_traits::lock_unique_ptr_t lock, work_thread_holder_t thread_holder)
A part of implementation of work thread with activity tracking.
so_5::stats::activity_tracking_stuff::stats_collector_t< so_5::stats::activity_tracking_stuff::internal_lock > m_waiting_stats
Statictics for wait activity.
with_activity_tracking_impl_t(queue_traits::lock_unique_ptr_t lock, work_thread_holder_t thread_holder)
so_5::stats::activity_tracking_stuff::stats_collector_t< so_5::stats::activity_tracking_stuff::internal_lock > m_working_stats
Statictics for work activity.
A worker thread for nef_one_thread dispatcher.
work_thread_template_t(queue_traits::lock_unique_ptr_t lock, work_thread_holder_t thread_holder)
Initializing constructor.
An analog of unique_ptr for abstract_work_thread.
work_thread_holder_t(work_thread_holder_t &&o) noexcept
Interface for dispatcher binders.
SObjectizer Environment.
stats::repository_t & stats_repository()
Access to repository of data sources for run-time monitoring.
An interface of event queue for agent.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
T & get() const noexcept
Base for the case of internal stats lock.
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
Some reusable and low-level classes/functions which can be used in public header files.
Various stuff related to MPSC event queue implementation and tuning.
void send_thread_activity_stats(const so_5::mbox_t &, const stats::prefix_t &, work_thread_no_activity_tracking_t &)
dispatcher_handle_t make_dispatcher(environment_t &env)
Create an instance of nef_one_thread 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 nef_one_thread dispatcher.
dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base)
Create an instance of nef_one_thread dispatcher.
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.
Details of SObjectizer run-time implementations.
Definition agent.cpp:780
void ensure_join_from_different_thread(current_thread_id_t thread_to_be_joined)
Ensures that join will be called from different thread.
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
const int rc_no_preallocated_resources_for_agent
There are no resources that must have been in place for an agent in advance.
Definition ret_code.hpp:481
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
current_thread_id_t query_current_thread_id()
Get the ID of the current thread.
outliving_reference_t< T > outliving_mutable(T &r)
Make outliving_reference wrapper for mutable reference.
demand_t * m_next
Next demand in the queue.
demand_t()=default
Default constructor.
execution_demand_t m_execution_demand
Execution demand to be used.
demand_t(execution_demand_t &&source)
Initializing constructor.
common_data_t(queue_traits::lock_unique_ptr_t lock, work_thread_holder_t thread_holder)
Initializing constructor.
A description of event execution demand.
void call_handler(current_thread_id_t thread_id)
Helper method to simplify demand execution.
A message with value of some quantity.
Definition messages.hpp:60
Information about one work thread activity.
Definition messages.hpp:108
activity_stats_t m_working_stats
Stats for processed events.
activity_stats_t m_waiting_stats
Stats for waiting periods.