SObjectizer 5.8
Loading...
Searching...
No Matches
st_env_infrastructure_reuse.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \file
7 * \brief Reusable stuff to be used in implementations of
8 * various single thread environment infrastructure.
9 *
10 * \since v.5.5.19
11 */
12
13#pragma once
14
15#include <so_5/environment_infrastructure.hpp>
16
17#include <so_5/impl/coop_repository_basis.hpp>
18#include <so_5/impl/mbox_iface_for_timers.hpp>
19
20#include <so_5/disp/reuse/data_source_prefix_helpers.hpp>
21
22#include <so_5/stats/impl/activity_tracking.hpp>
23#include <so_5/stats/impl/st_env_stuff.hpp>
24#include <so_5/stats/controller.hpp>
25#include <so_5/stats/repository.hpp>
26#include <so_5/stats/prefix.hpp>
27#include <so_5/stats/messages.hpp>
28#include <so_5/stats/std_names.hpp>
29
30#include <so_5/send_functions.hpp>
31#include <so_5/env_infrastructures.hpp>
32
33#include <so_5/timers.hpp>
34
35#include <deque>
36
37namespace so_5 {
38
39namespace env_infrastructures {
40
42
43//! A short name for namespace with run-time stats stuff.
44namespace stats = ::so_5::stats;
45
46/*!
47 * \brief Status of shutdown procedure.
48 *
49 * \since v.5.5.19
50 */
52 {
53 //! Shutdown is not started yet.
55 //! Shutdown must be started as soon as possible.
57 //! Shutdown is initiated but not finished yet.
59 //! Shutdown completed and work of environment must be finished.
61 };
62
63//
64// fake_activity_tracker_t
65//
66/*!
67 * \brief An implementation of work thread activity tracking stuff for
68 * the case when activity tracking is not used.
69 *
70 * \since v.5.5.19
71 */
72struct fake_activity_tracker_t final
73 {
74 void wait_started() {}
76 void wait_stopped() {}
77
78 void work_started() {}
79 void work_stopped() {}
80 };
81
82//
83// real_activity_tracker_t
84//
85/*!
86 * \brief An implementation of work thread activity tracking stuff for
87 * the case when activity tracking is used.
88 *
89 * \attention
90 * There is no need to use some sync object (like mutex or spin_lock) because
91 * all actions with activity tracker will be done on the context of
92 * single thread.
93 *
94 * \since v.5.5.19
95 */
125
126inline void
128 const mbox_t &,
129 const stats::prefix_t &,
130 const current_thread_id_t &,
131 fake_activity_tracker_t & )
132 {
133 /* Nothing to do */
134 }
135
136inline void
138 const so_5::mbox_t & mbox,
139 const stats::prefix_t & prefix,
140 const current_thread_id_t & thread_id,
141 real_activity_tracker_t & activity_tracker )
142 {
144 mbox,
145 prefix,
147 thread_id,
148 activity_tracker.take_activity_stats() );
149 }
150
151//
152// coop_repo_t
153//
154/*!
155 * \brief Implementation of coop_repository for
156 * single-threaded environment infrastructure.
157 *
158 * \since v.5.5.19
159 */
160class coop_repo_t final
162 {
163 public :
164 //! Initializing constructor.
166 //! SObjectizer Environment.
168 //! Cooperation action listener.
169 coop_listener_unique_ptr_t coop_listener )
170 : coop_repository_basis_t{ env, std::move(coop_listener) }
171 {}
172
173 //! Is there any live coop?
174 bool
176 {
177 // A lock is necessary here because coop_repo can be used
178 // in thread-safe environment where access to environment from
179 // different thread is allowed.
180 std::lock_guard< std::mutex > l{ m_lock };
181 return 0u != m_registrations_in_progress ||
182 0u != m_total_coops;
183 }
184 };
185
186//
187// default_dispatcher_basis_t
188//
189/*!
190 * \brief A basic part of implementation of dispatcher to be used in
191 * places where default dispatcher is needed.
192 *
193 * \note
194 * This part is not dependent of activity tracking policy which can be used in
195 * derived classes.
196 *
197 * \note
198 * Implements disp_binder_t interface.
199 *
200 * \tparam Event_Queue_Type An actual type of event queue.
201 *
202 * \since v.5.5.19, v.5.6.0
203 */
204template< typename Event_Queue_Type >
206 {
207 public :
209 outliving_reference_t< Event_Queue_Type > event_queue )
210 : m_event_queue{ std::move(event_queue) }
212 {}
213
214 void
216 execution_demand_t & demand )
217 {
219 }
220
221 Event_Queue_Type &
222 event_queue() const noexcept
223 {
224 return m_event_queue.get();
225 }
226
227 current_thread_id_t
228 thread_id() const noexcept
229 {
230 return m_thread_id;
231 }
232
233 void
235 agent_t & /*agent*/ ) override
236 {
237 // Nothing to do.
238 }
239
240 void
242 agent_t & /*agent*/ ) noexcept override
243 {
244 // Nothing to do.
245 }
246
247 void
249 agent_t & agent ) noexcept override
250 {
251 agent.so_bind_to_dispatcher( this->event_queue() );
253 }
254
255 void
257 agent_t & /*agent*/ ) noexcept override
258 {
260 }
261
262 std::size_t
263 agents_bound() const noexcept
264 {
265 return m_agents_bound.load( std::memory_order_relaxed );
266 }
267
268 protected :
269 //! Event queue for that dispatcher.
271
272 //! ID of the main thread.
273 /*!
274 * Will be passed to event handlers which are called on the context
275 * of the main thread.
276 *
277 * \note
278 * Receives value in the constructor.
279 */
280 current_thread_id_t m_thread_id;
281
282 //! Counter of agents bound to that dispatcher.
283 std::atomic< std::size_t > m_agents_bound{ 0 };
284 };
285
286//
287// default_dispatcher_t
288//
289/*!
290 * \brief An implementation of dispatcher to be used in
291 * places where default dispatcher is needed.
292 *
293 * \note
294 * Implements disp_binder_t interface (via inheritance from
295 * default_dispatcher_basis_t).
296 *
297 * \tparam Event_Queue_Type a type of actual event queue for the dispatcher.
298 *
299 * \tparam Activity_Tracker a type of activity tracker to be used
300 * for run-time statistics.
301 *
302 * \tparam Data_Source_Name_Parts a type with methods for generation
303 * of names for dispatcher's data sources. Must be a type like that:
304 * \code
305 struct disp_ds_name_parts_t
306 {
307 static const char * disp_type_part() { return "mtsafe_st_env"; }
308 };
309 * \endcode
310 *
311 * \note
312 * This type is not marked as final because it can be used as a base
313 * class in external projects (like so_5_extra).
314 *
315 * \since v.5.6.0
316 */
317template<
318 typename Event_Queue_Type,
319 typename Activity_Tracker,
320 typename Data_Source_Name_Parts >
322 : public default_dispatcher_basis_t< Event_Queue_Type >
323 {
324 public :
327 outliving_reference_t< Event_Queue_Type > event_queue,
328 outliving_reference_t< Activity_Tracker > activity_tracker )
329 : default_dispatcher_basis_t< Event_Queue_Type >{
330 std::move(event_queue) }
333 outliving_mutable( *this )
334 }
335 , m_activity_tracker{ std::move(activity_tracker) }
336 {}
337
338 Activity_Tracker &
340 {
341 return m_activity_tracker.get();
342 }
343
344 private :
345
346 /*!
347 * \brief Data source for run-time monitoring of whole dispatcher.
348 *
349 * \since v.5.5.19
350 */
351 class disp_data_source_t final : public stats::source_t
352 {
353 //! Dispatcher to work with.
355
356 //! Basic prefix for data sources.
358
359 public :
362 : m_dispatcher{ disp }
363 {
364 // Name of data source should be constructed.
365 using namespace so_5::disp::reuse;
366
367 m_base_prefix = make_disp_prefix(
368 Data_Source_Name_Parts::disp_type_part(),
369 "DEFAULT",
370 &m_dispatcher.get() );
371 }
372
373 void
374 distribute( const mbox_t & mbox ) override
375 {
376 so_5::send< stats::messages::quantity< std::size_t > >(
377 mbox,
380 m_dispatcher.get().agents_bound() );
381
382 const auto evt_queue_stats =
383 m_dispatcher.get().event_queue().query_stats();
384 so_5::send< stats::messages::quantity< std::size_t > >(
385 mbox,
388 evt_queue_stats.m_demands_count );
389
390 send_thread_activity_stats(
391 mbox,
393 m_dispatcher.get().thread_id(),
394 m_dispatcher.get().activity_tracker() );
395 }
396 };
397
398 //! Data source for speading run-time stats.
399 stats::auto_registered_source_holder_t< disp_data_source_t >
401
402 //! Activity tracker.
404 };
405
406//
407// actual_elapsed_timers_collector_t
408//
409/*!
410 * \brief Implementation of elapsed_timers_collector interface.
411 *
412 * \since v.5.5.19
413 */
414class actual_elapsed_timers_collector_t final
416 {
417 //! Type of demand created from elapsed timer.
418 struct demand_t
419 {
420 std::type_index m_type_index;
421 mbox_t m_mbox;
422 message_ref_t m_message;
423
425 std::type_index type_index,
426 mbox_t mbox,
427 message_ref_t message )
428 : m_type_index( std::move(type_index) )
429 , m_mbox( std::move(mbox) )
430 , m_message( std::move(message) )
431 {}
432 };
433
434 //! Type of container for demands.
435 using demands_container_t = std::deque< demand_t >;
436
437 //! Collected demands.
438 demands_container_t m_demands;
439
440 public :
441 virtual void
443 std::type_index type_index,
444 mbox_t mbox,
445 message_ref_t msg ) override
446 {
447 m_demands.emplace_back(
448 std::move(type_index),
449 std::move(mbox),
450 std::move(msg) );
451 }
452
453 /*!
454 * \return true if there is no any pending demands.
455 */
456 bool
457 empty() const noexcept
458 {
459 return m_demands.empty();
460 }
461
462 /*!
463 * Convert all demands into actual message sends.
464 */
465 void
467 {
468 for( auto & d : m_demands )
469 {
472 }
473
474 // A defense from cases where were too many timers.
475 if( m_demands.size() < 1000 )
476 // A simple clean is enough.
477 m_demands.clear();
478 else
479 {
480 // Old container must be utilized.
481 demands_container_t demands;
482 swap( demands, m_demands );
483 }
484 }
485 };
486
487//
488// direct_delivery_elapsed_timers_collector_t
489//
490/*!
491 * \brief Implementation of elapsed_timers_collector interface which
492 * is not multi-thread safe.
493 *
494 * This implementation is intended to use in not-mtsafe environment
495 * infrastructures where is possible to transform elapsed timer into
496 * a demand directly.
497 *
498 * It means that actual delivery is performed in accept() method.
499 *
500 * \since v.5.5.19
501 */
502class direct_delivery_elapsed_timers_collector_t final
504 {
505 public :
506 virtual void
508 std::type_index type_index,
509 mbox_t mbox,
510 message_ref_t msg ) override
511 {
513 .deliver_message_from_timer( type_index, msg );
514 }
515 };
516
517//
518// stats_controller_t
519//
520/*!
521 * \brief Implementation of stats_controller for that type of
522 * single-threaded environment.
523 *
524 * \tparam Lock_Holder a type for defense from multi-threaded access.
525 * Expected to be so_5::details::actual_lock_holder_t or
526 * so_5::details::no_lock_holder_t.
527 *
528 * \since v.5.5.19
529 */
530template< typename Lock_Holder >
531class stats_controller_t final
532 : public stats::controller_t
533 , public stats::repository_t
534 , public stats::impl::st_env_stuff::next_turn_handler_t
535 , protected Lock_Holder
536 {
537 public :
538 //! Initializing constructor.
540 //! Mbox for sending messages with run-time statistics.
541 mbox_t distribution_mbox,
542 //! Mbox for delayed messages for initiation of next turn.
543 mbox_t next_turn_mbox )
544 : m_distribution_mbox( std::move(distribution_mbox) )
545 , m_next_turn_mbox( std::move(next_turn_mbox) )
546 {}
547
548 // Implementation of controller_t interface.
549 virtual const mbox_t &
550 mbox() const override
551 {
552 return m_distribution_mbox;
553 }
554
555 virtual void
556 turn_on() override
557 {
558 this->lock_and_perform( [&]{
559 if( status_t::off == m_status )
560 {
561 // Do the part where exceptions are possible.
562 const auto run_id = m_run_id + 1;
563
565
566 // We don't expect exceptions from here.
567 m_status = status_t::on;
568 m_run_id = run_id;
569 }
570 } );
571 }
572
573 virtual void
574 turn_off() override
575 {
576 this->lock_and_perform( [&] {
577 m_status = status_t::off;
578 } );
579 }
580
581 virtual std::chrono::steady_clock::duration
583 std::chrono::steady_clock::duration period ) override
584 {
585 return this->lock_and_perform( [&] {
586 auto ret_value = m_distribution_period;
587
588 m_distribution_period = period;
589
590 return ret_value;
591 } );
592 }
593
594 // Implementation of repository_t interface.
595 virtual void
596 add( stats::source_t & what ) override
597 {
598 this->lock_and_perform( [&] {
600 } );
601 }
602
603 virtual void
604 remove( stats::source_t & what ) noexcept override
605 {
606 this->lock_and_perform( [&] {
608 } );
609 }
610
611 // Implementation of next_turn_handler_t interface.
612 virtual void
613 on_next_turn( int run_id ) override
614 {
615 this->lock_and_perform( [&] {
616 if( status_t::on == m_status && run_id == m_run_id )
617 {
618 const auto actual_duration = distribute_current_data();
619
620 if( actual_duration < m_distribution_period )
621 // There is some time to sleep.
623 m_distribution_period - actual_duration,
624 m_run_id );
625 else
626 // We must distribute next portion of data
627 // without long waiting.
629 }
630 } );
631 }
632
633 private :
634 //! Status of stats_controller.
635 enum class status_t
636 {
637 off,
638 on
639 };
640
641 //! Mbox for sending messages with run-time statistics.
643 //! Mbox for delayed messages for initiation of next turn.
644 const mbox_t m_next_turn_mbox;
645
646 //! Object's lock.
647 /*!
648 * In single-threaded invironment we need to have only one lock.
649 */
650 std::mutex m_lock;
651
652 //! Current status of stats_controller.
654
655 //! ID of stats distribution.
656 /*!
657 * Will be increased on every turn_on call.
658 */
659 int m_run_id{ 0 };
660
661 /*!
662 * \name Data sources-related part of controller's data.
663 * \{
664 */
665 //! Head of data sources list.
666 stats::source_t * m_head = { nullptr };
667 //! Tail of data sources list.
668 stats::source_t * m_tail = { nullptr };
669
670 std::chrono::steady_clock::duration m_distribution_period{
672 /*!
673 * \}
674 */
675
676 static std::chrono::steady_clock::duration
678 {
679 return std::chrono::milliseconds{1};
680 }
681
682 //! Actual distribution of the current statistics.
683 std::chrono::steady_clock::duration
685 {
686 auto started_at = std::chrono::steady_clock::now();
687
690
691 auto s = m_head;
692 while( s )
693 {
695
696 s = source_list_next( *s );
697 }
698
701
702 return std::chrono::steady_clock::now() - started_at;
703 }
704
705 //! Helper method for sending next instance of next_turn message.
706 void
708 std::chrono::steady_clock::duration pause,
709 const int run_id )
710 {
711 send_delayed< next_turn >(
713 pause,
714 outliving_mutable( *this ),
715 run_id );
716 }
717 };
718
719} /* namespace st_reusable_stuff */
720
721} /* namespace env_infrastructures */
722
723} /* 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
Type of smart handle for a cooperation.
A special type that plays role of unique_ptr for coop.
Definition coop.hpp:1342
A class to be used as mixin with actual std::mutex instance inside.
Interface for dispatcher binders.
Default implementation of multithreaded environment infrastructure.
std::shared_ptr< default_dispatcher_t< Activity_Tracker > > m_default_disp
Dispatcher to be used as default dispatcher.
stats::repository_t & stats_repository() noexcept override
Get stats repository for the environment.
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.
reusable::actual_elapsed_timers_collector_t m_timers_collector
A collector for elapsed timers.
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).
void launch(env_init_t init_fn) override
Do actual launch of SObjectizer's Environment.
coop_handle_t register_coop(coop_unique_holder_t coop) override
Register new cooperation.
void stop() noexcept override
Initiate a signal for shutdown of Environment.
so_5::impl::final_dereg_chain_holder_t m_final_dereg_chain
The chain of coops for the final deregistration.
void perform_shutdown_related_actions_if_needed(std::unique_lock< std::mutex > &acquired_lock) noexcept
main_thread_sync_objects_t m_sync_objects
All sync objects to be shared between different parts.
void try_handle_next_demand(std::unique_lock< std::mutex > &acquired_lock) noexcept
timer_thread_stats_t query_timer_thread_stats() override
Query run-time statistics for timer (thread or manager).
void process_final_deregs_if_any(std::unique_lock< std::mutex > &acquired_lock) noexcept
so_5::environment_infrastructure_t::coop_repository_stats_t query_coop_repository_stats() override
Query run-time statistics for cooperation repository.
coop_unique_holder_t make_coop(coop_handle_t parent, disp_binder_shptr_t default_binder) override
Create an instance of a new coop.
bool final_deregister_coop(coop_shptr_t coop) noexcept override
Do final actions of the cooperation deregistration.
event_queue_impl_t m_event_queue
Queue for execution_demands which must be handled on the main thread.
env_infrastructure_t(environment_t &env, timer_manager_factory_t timer_factory, error_logger_shptr_t error_logger, coop_listener_unique_ptr_t coop_listener, mbox_t stats_distribution_mbox)
disp_binder_shptr_t make_default_disp_binder() override
Create a binder for the default dispatcher.
void handle_expired_timers_if_any(std::unique_lock< std::mutex > &acquired_lock) noexcept
stats::controller_t & stats_controller() noexcept override
Get stats controller for the environment.
Activity_Tracker m_activity_tracker
Actual activity tracker for main working thread.
Parameters for simple thread-safe single-thread environment.
const timer_manager_factory_t & timer_manager() const
Getter for timer_manager factory.
virtual void accept(std::type_index type_index, mbox_t mbox, message_ref_t msg) override
Accept and store info about elapsed timer.
coop_repo_t(outliving_reference_t< environment_t > env, coop_listener_unique_ptr_t coop_listener)
Initializing constructor.
A basic part of implementation of dispatcher to be used in places where default dispatcher is needed.
std::atomic< std::size_t > m_agents_bound
Counter of agents bound to that dispatcher.
outliving_reference_t< Event_Queue_Type > m_event_queue
Event queue for that dispatcher.
default_dispatcher_basis_t(outliving_reference_t< Event_Queue_Type > event_queue)
void bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
void undo_preallocation(agent_t &) noexcept override
Undo resources allocation.
void unbind(agent_t &) noexcept override
Unbind agent from dispatcher.
void preallocate_resources(agent_t &) override
Allocate resources in dispatcher for new agent.
outliving_reference_t< default_dispatcher_t > m_dispatcher
Dispatcher to work with.
void distribute(const mbox_t &mbox) override
Send appropriate notification about the current value.
An implementation of dispatcher to be used in places where default dispatcher is needed.
outliving_reference_t< Activity_Tracker > m_activity_tracker
Activity tracker.
stats::auto_registered_source_holder_t< disp_data_source_t > m_data_source
Data source for speading run-time stats.
default_dispatcher_t(outliving_reference_t< environment_t > env, outliving_reference_t< Event_Queue_Type > event_queue, outliving_reference_t< Activity_Tracker > activity_tracker)
virtual void accept(std::type_index type_index, mbox_t mbox, message_ref_t msg) override
Accept and store info about elapsed timer.
stats::activity_tracking_stuff::stats_collector_t< stats::activity_tracking_stuff::null_lock > m_waiting
stats::activity_tracking_stuff::stats_collector_t< stats::activity_tracking_stuff::null_lock > m_working
const mbox_t m_next_turn_mbox
Mbox for delayed messages for initiation of next turn.
const mbox_t m_distribution_mbox
Mbox for sending messages with run-time statistics.
virtual void add(stats::source_t &what) override
Registration of new data source.
virtual std::chrono::steady_clock::duration set_distribution_period(std::chrono::steady_clock::duration period) override
Set distribution period.
void send_next_message(std::chrono::steady_clock::duration pause, const int run_id)
Helper method for sending next instance of next_turn message.
virtual const mbox_t & mbox() const override
Get the mbox for receiving monitoring information.
stats_controller_t(mbox_t distribution_mbox, mbox_t next_turn_mbox)
Initializing constructor.
std::chrono::steady_clock::duration distribute_current_data()
Actual distribution of the current statistics.
virtual void remove(stats::source_t &what) noexcept override
Deregistration of previously registered data source.
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.
work_thread_activity_tracking_t work_thread_activity_tracking() const
Get activity tracking flag for the whole SObjectizer Environment.
const error_logger_shptr_t & so5_error_logger() const
Get error logger for the environment.
SObjectizer Environment.
stats::repository_t & stats_repository()
Access to repository of data sources for run-time monitoring.
An interface of event queue for agent.
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.
std::size_t m_registrations_in_progress
Count of coops those are in registration now.
environment_infrastructure_t::coop_repository_stats_t query_stats()
Get the current statistic for run-time monitoring.
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.
Helper class for accessing protected members from mbox interface.
void deliver_message_from_timer(const std::type_index &msg_type, const message_ref_t &message)
intrusive_ptr_t(intrusive_ptr_t &&o) noexcept
Move constructor.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
T & get() const noexcept
void start_if_not_started()
A helper method for safe start if start method hasn't been called yet.
A holder for data-souce that should be automatically registered and deregistered in registry.
A public interface for control SObjectizer monitoring options.
static std::chrono::steady_clock::duration default_distribution_period()
Default distribution period.
An interface for initiation of next turn in stats distribution.
static mbox_t make(environment_t &env)
Helper for simplify creation of that mboxes of that type.
A type for storing prefix of data_source name.
Definition prefix.hpp:32
An interface of data sources repository.
static source_t * source_list_next(const source_t &what) noexcept
Helper method for accessing next data source in the list.
static void source_list_add(source_t &what, source_t *&head, source_t *&tail) noexcept
Helper method for adding data source to existing list.
static void source_list_remove(source_t &what, source_t *&head, source_t *&tail) noexcept
Helper method for removing data source from existing list.
An interface of data source.
virtual void distribute(const mbox_t &)=0
Send appropriate notification about the current value.
An indentificator for the timer.
Definition timers.hpp:73
An interface for collector of elapsed timers.
Definition timers.hpp:436
Timer manager interface.
Definition timers.hpp:409
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 std::chrono::steady_clock::duration timeout_before_nearest_timer(std::chrono::steady_clock::duration default_timer)=0
Calculate time before the nearest timer (if any).
virtual void process_expired_timers()=0
Translation of expired timers into message sends.
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.
virtual timer_thread_stats_t query_stats()=0
Get statistics for run-time monitoring.
#define SO_5_FUNC
Definition declspec.hpp:48
Some reusable and low-level classes/functions which can be used in public header files.
Reusable components for dispatchers.
Event dispatchers.
auto unlock_do_and_lock_again(std::unique_lock< std::mutex > &acquired_lock, Action &&action) -> decltype(action())
main_thread_status_t
A short name for namespace with run-time stats stuff.
void wakeup_if_waiting(main_thread_sync_objects_t &sync_objects)
Simple single-threaded environment infrastructure with thread safety.
SO_5_FUNC environment_infrastructure_factory_t factory(params_t &&params)
A factory for creation of simple thread-safe single-thread environment infrastructure object.
Various reusable stuff which can be used in implementation of single-threaded environment infrastruct...
shutdown_status_t
A short name for namespace with run-time stats stuff.
@ must_be_started
Shutdown must be started as soon as possible.
@ completed
Shutdown completed and work of environment must be finished.
@ in_progress
Shutdown is initiated but not finished yet.
void send_thread_activity_stats(const so_5::mbox_t &mbox, const stats::prefix_t &prefix, const current_thread_id_t &thread_id, real_activity_tracker_t &activity_tracker)
void send_thread_activity_stats(const mbox_t &, const stats::prefix_t &, const current_thread_id_t &, fake_activity_tracker_t &)
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 wrap_init_fn_call(Init_Fn init_fn)
A special wrapper for calling init function.
Internal implementation of run-time monitoring and statistics related stuff.
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
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
work_thread_activity_tracking_t
Values for dispatcher's work thread activity tracking.
Definition types.hpp:75
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.
A special class for generation of names for dispatcher data sources.
A bunch of sync objects which need to be shared between various parts of env_infrastructure.
std::condition_variable m_wakeup_condition
A condition to sleep on when no activities to handle.
Statistical data for run-time monitoring of coop repository content.
std::size_t m_total_coop_count
Count of cooperations inside the environment.
A description of event execution demand.
void call_handler(current_thread_id_t thread_id)
Helper method to simplify demand execution.
A special class for cases where lock is not needed at all.
Notification about finish of stats distribution.
Definition messages.hpp:100
Notification about start of new stats distribution.
Definition messages.hpp:90
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.
Statistics for run-time monitoring.
Definition timers.hpp:120