SObjectizer 5.8
Loading...
Searching...
No Matches
final_dereg_chain_helpers.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \file
7 * \brief Helpers for working with a chain of coops for the final deregistration.
8 * \since v.5.8.0
9 */
10
11#pragma once
12
13#include <so_5/impl/coop_private_iface.hpp>
14#include <so_5/impl/internal_env_iface.hpp>
15
16#include <so_5/coop.hpp>
17
18#include <utility>
19
20namespace so_5::impl
21{
22
23//
24// final_dereg_chain_holder_t
25//
26/*!
27 * \brief Helper class for holding the current chain of coops for
28 * the final deregistration.
29 *
30 * This chain is an intrusive list (via coop_t::m_next_in_final_dereg_chain),
31 * but it's necessary to hold the head and the tail of this chain.
32 * Class final_dereg_chain_holder_t does exactly that: it holds the
33 * current head, the tail and the number of items it the chain.
34 *
35 * New items have to be added by append() method.
36 *
37 * When the current chain has to be processed it must be extracted
38 * from the holder by using giveout_current_chain() method.
39 *
40 * \attention
41 * This class isn't thread-safe. If thread-safety is necessary then
42 * it should be provided by a user of this class.
43 *
44 * \note
45 * This class isn't Copyable, not Moveable.
46 *
47 * \since v.5.8.0
48 */
50 {
51 /*!
52 * \brief Number of items in the chain of coops for the final
53 * deregistration.
54 *
55 * This value is necessary for stats.
56 *
57 * \since v.5.8.0
58 */
60
61 /*!
62 * \brief The head of the chain of coops for the final deregistration.
63 *
64 * It may be nullptr. It means that the chain is empty now.
65 *
66 * \since v.5.8.0
67 */
69
70 /*!
71 * \brief The tail of the chain of coops for the final deregistration.
72 *
73 * This value is used for fast addition of a new coop to the chain.
74 *
75 * It may be nullptr in the case when the chain is empty.
76 *
77 * \since v.5.8.0
78 */
80
81 public:
83#if 1
85#else
86 //NOTE: this code was kept here for testing purposes.
88 {
89 if( 0u != m_final_dereg_chain_size )
90 {
91 std::cerr << "*** ~final_dereg_chain_holder_t: "
92 "unexpected m_final_dereg_chain_size: "
94 << std::endl;
95 std::abort();
96 }
97 }
98#endif
99
101 const final_dereg_chain_holder_t & ) = delete;
104 const final_dereg_chain_holder_t & ) = delete;
105
107 final_dereg_chain_holder_t && ) = delete;
110 final_dereg_chain_holder_t && ) = delete;
111
112 void
124
125 [[nodiscard]]
126 std::size_t
127 size() const noexcept
128 {
130 }
131
132 [[nodiscard]]
133 bool
134 empty() const noexcept
135 {
136 return !static_cast<bool>( m_final_dereg_chain_head );
137 }
138
139 [[nodiscard]]
140 coop_shptr_t
142 {
143 coop_shptr_t head = std::exchange(
145 coop_shptr_t{} );
146 m_final_dereg_chain_tail = coop_shptr_t{};
148
149 return head;
150 }
151 };
152
153//
154// process_final_dereg_chain
155//
156/*!
157 * \brief Helper function that does proceesing of final dereg chain.
158 *
159 * Usage example:
160 * \code
161 * final_dereg_chain_holder_t holder;
162 * ...
163 * holder.append(coop);
164 * ...
165 * holder.append(coop);
166 * ...
167 * process_final_dereg_chain(holder.giveout_current_chain());
168 * \endcode
169 *
170 * \since v.5.8.0
171 */
172inline void
173process_final_dereg_chain( coop_shptr_t head ) noexcept
174 {
175 // Do final_deregister_coop for every item in the chain
176 // one by one.
177 while( head )
178 {
179 coop_shptr_t next =
181 *head );
182 auto & env = head->environment();
184 std::move(head) );
185
186 head = std::move(next);
187 }
188 }
189
190} /* namespace so_5::impl */
Type of smart handle for a cooperation.
environment_t & environment() const noexcept
Access to SO Environment for which cooperation is bound.
Definition coop.hpp:453
A special type that plays role of unique_ptr for coop.
Definition coop.hpp:1342
Alias for namespace with traits of event queue.
A handle for nef_one_thread dispatcher.
disp_binder_shptr_t binder() const noexcept
Get a binder for that dispatcher.
void reset() noexcept
Drop the content of handle.
Alias for namespace with traits of event queue.
A handle for one_thread dispatcher.
disp_binder_shptr_t binder() const noexcept
Get a binder for that dispatcher.
void reset() noexcept
Drop the content of handle.
void start_deregistration()
Initiate start of the cooperation deregistration.
void ready_to_deregister_notify(coop_shptr_t coop)
Notification about readiness of the cooperation deregistration.
std::condition_variable m_final_dereg_chain_cond
Notification object to inform that the chain of coops for the final deregistration isn't empty anymor...
bool final_deregister_coop(coop_shptr_t coop) noexcept
Do final actions of the cooperation deregistration.
void process_current_final_dereg_chain(std::unique_lock< std::mutex > &lck) noexcept
Method that performs the final deregistration for coops in the m_final_dereg_chain.
so_5::impl::final_dereg_chain_holder_t m_final_dereg_chain
The chain of coops for the final deregistration.
std::mutex m_final_dereg_chain_lock
Lock object for thread-safety of the chain of coops ready for the final deregistration.
coop_repo_t(outliving_reference_t< environment_t > env, coop_listener_unique_ptr_t coop_listener)
Initializing constructor.
void wait_all_coop_to_deregister()
Wait for end of all cooperations deregistration.
void final_dereg_thread_body()
Method that implements the body of final deregistration thread.
std::condition_variable m_deregistration_started_cond
Condition variable for the deregistration start indication.
bool m_final_dereg_thread_shutdown_flag
The flag for shutting down the final deregistration thread.
std::condition_variable m_deregistration_finished_cond
Condition variable for the deregistration finish indication.
environment_infrastructure_t::coop_repository_stats_t query_stats()
Get the current statistic for run-time monitoring.
std::thread m_final_dereg_thread
A separate thread for doing the final deregistration.
void wait_for_start_deregistration()
Wait for a signal about start of the cooperation deregistration.
Default implementation of multithreaded environment infrastructure.
so_5::timer_id_t schedule_timer(const std::type_index &type_wrapper, const message_ref_t &msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period) override
Initiate a timer (delayed or periodic message).
::so_5::stats::repository_t & stats_repository() noexcept override
Get stats repository for the environment.
const environment_params_t::default_disp_params_t m_default_dispatcher_params
Parameters for the default dispatcher.
timer_thread_stats_t query_timer_thread_stats() override
Query run-time statistics for timer (thread or manager).
void single_timer(const std::type_index &type_wrapper, const message_ref_t &msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause) override
Initiate a delayed message.
void stop() noexcept override
Initiate a signal for shutdown of Environment.
coop_handle_t register_coop(coop_unique_holder_t coop) override
Register new cooperation.
::so_5::stats::controller_t & stats_controller() noexcept override
Get stats controller for the environment.
timer_thread_unique_ptr_t m_timer_thread
Timer thread to be used by the environment.
bool final_deregister_coop(coop_shptr_t coop_name) noexcept override
Do final actions of the cooperation deregistration.
void launch(env_init_t init_fn) override
Do actual launch of SObjectizer's Environment.
mt_env_infrastructure_t(environment_t &env, environment_params_t::default_disp_params_t default_disp_params, timer_thread_unique_ptr_t timer_thread, coop_listener_unique_ptr_t coop_listener, mbox_t stats_distribution_mbox)
Initializing constructor.
coop_unique_holder_t make_coop(coop_handle_t parent, disp_binder_shptr_t default_binder) override
Create an instance of a new coop.
coop_repository_stats_t query_coop_repository_stats() override
Query run-time statistics for cooperation repository.
::so_5::stats::impl::std_controller_t m_stats_controller
Run-time stats controller to be used by the environment.
environment_t & m_env
SOEnv for that this infrastructure was created.
disp_binder_shptr_t make_default_disp_binder() override
Create a binder for the default dispatcher.
An interface for environment_infrastructure entity.
static environment_infrastructure_deleter_fnptr_t default_deleter()
Default deleter for environment_infrastructure object.
Parameters for the SObjectizer Environment initialization.
coop_listener_unique_ptr_t so5_giveout_coop_listener()
Get cooperation listener.
so_5::timer_thread_factory_t so5_giveout_timer_thread_factory()
Get the timer_thread factory.
const default_disp_params_t & default_disp_params() const
Get the parameters for the default dispatcher.
const error_logger_shptr_t & so5_error_logger() const
Get error logger for the environment.
SObjectizer Environment.
A special class for accessing private members of agent_coop.
static void set_next_in_final_dereg_chain(coop_t &coop, coop_shptr_t next_in_chain) noexcept
Set the next coop in the chain of coops for the final deregistration.
static coop_shptr_t giveout_next_in_final_dereg_chain(coop_t &coop) noexcept
Extract a smart pointer to the next coop in the chain of coops for the final deregistration.
A basic part for various implementations of coop_repository.
std::size_t m_total_coops
Total count of coops.
std::mutex m_lock
Lock for coop repository.
coop_unique_holder_t make_coop(coop_handle_t parent, disp_binder_shptr_t default_binder)
Create an instance of a new coop.
void deregister_all_coop() noexcept
Deregisted all cooperations.
coop_repository_basis_t(outliving_reference_t< environment_t > environment, coop_listener_unique_ptr_t coop_listener)
final_deregistration_result_t final_deregister_coop(coop_shptr_t coop) noexcept
Do final actions of the cooperation deregistration.
try_switch_to_shutdown_result_t
Result of attempt to switch to shutdown state.
environment_infrastructure_t::coop_repository_stats_t query_stats()
Get the current statistic for run-time monitoring.
status_t
Enumeration of possible repository statuses.
try_switch_to_shutdown_result_t try_switch_to_shutdown() noexcept
Try to switch repository to shutdown state.
coop_handle_t register_coop(coop_unique_holder_t agent_coop)
Register cooperation.
Helper class for holding the current chain of coops for the final deregistration.
final_dereg_chain_holder_t & operator=(const final_dereg_chain_holder_t &)=delete
final_dereg_chain_holder_t(const final_dereg_chain_holder_t &)=delete
final_dereg_chain_holder_t & operator=(final_dereg_chain_holder_t &&)=delete
coop_shptr_t m_final_dereg_chain_tail
The tail of the chain of coops for the final deregistration.
std::size_t m_final_dereg_chain_size
Number of items in the chain of coops for the final deregistration.
coop_shptr_t m_final_dereg_chain_head
The head of the chain of coops for the final deregistration.
final_dereg_chain_holder_t(final_dereg_chain_holder_t &&)=delete
A helper class for accessing the functionality of environment-class which is specific for SObjectizer...
void final_deregister_coop(coop_shptr_t coop) noexcept
Do the final actions of a cooperation deregistration.
internal_env_iface_t(environment_t &env)
Initializing constructor.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
A public interface for control SObjectizer monitoring options.
An interface of data sources repository.
An indentificator for the timer.
Definition timers.hpp:73
virtual void finish()=0
Finish timer and wait for full stop.
virtual void schedule_anonymous(const std::type_index &type_index, const mbox_t &mbox, const message_ref_t &msg, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)=0
Push anonymous delayed/periodic message to the timer queue.
virtual timer_thread_stats_t query_stats()=0
Get statistics for run-time monitoring.
virtual void start()=0
Launch timer.
virtual timer_id_t schedule(const std::type_index &type_index, const mbox_t &mbox, const message_ref_t &msg, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)=0
Push delayed/periodic message to the timer queue.
#define SO_5_FUNC
Definition declspec.hpp:48
Some reusable and low-level classes/functions which can be used in public header files.
auto do_with_rollback_on_exception(Main_Action main_action, Rollback_Action rollback_action) -> decltype(main_action())
Helper function for do some action with rollback in the case of an exception.
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 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.
Event dispatchers.
Default multi-threaded environment infrastructure.
SO_5_FUNC environment_infrastructure_factory_t factory()
A factory for creation the default multitheading environment infrastructure.
Various implementations of environment_infrastructure.
Details of SObjectizer run-time implementations.
Definition agent.cpp:780
void process_final_dereg_chain(coop_shptr_t head) noexcept
Helper function that does proceesing of final dereg chain.
void run_stage(const std::string &stage_name, Init_Fn &&init_fn, Deinit_Fn &&deinit_fn, Next_Stage &&next_stage)
Helper template function for doing initialization phase with rollback on failure.
Definition run_stage.hpp:31
void wrap_init_fn_call(Init_Fn init_fn)
A special wrapper for calling init function.
timer_thread_unique_ptr_t create_appropriate_timer_thread(error_logger_shptr_t error_logger, const timer_thread_factory_t &user_factory)
Helper function for timer_thread creation.
Definition timers.hpp:754
Internal implementation of run-time monitoring and statistics related stuff.
All stuff related to run-time monitoring and statistics.
Private part of message limit implementation.
Definition agent.cpp:33
outliving_reference_t< T > outliving_mutable(T &r)
Make outliving_reference wrapper for mutable reference.
disp_binder_shptr_t operator()(so_5::disp::one_thread::dispatcher_handle_t &handle) const
disp_binder_shptr_t operator()(so_5::disp::nef_one_thread::dispatcher_handle_t &handle) const
mt_env_infrastructure_t::default_dispatcher_holder_t operator()(const so_5::disp::one_thread::disp_params_t &params) const
mt_env_infrastructure_t::default_dispatcher_holder_t operator()(const so_5::disp::nef_one_thread::disp_params_t &params) const
Statistical data for run-time monitoring of coop repository content.
std::size_t m_total_coop_count
Count of cooperations inside the environment.
Statistics for run-time monitoring.
Definition timers.hpp:120