SObjectizer 5.8
Loading...
Searching...
No Matches
timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler > Class Template Reference

An engine for timer list mechanism. More...

#include <all.hpp>

Inheritance diagram for timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >:
timertt::details::engine_common< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >

Classes

struct  timer_type
 Type of list timer. More...
 

Public Types

typedef timer_list_engine_defaults defaults_type
 Type with default parameters for this engine.
 
using timer_action = typename base_type::timer_action
 Alias for timer_action type.
 
using scoped_timer_object
 Alias for scoped timer object.
 
- Public Types inherited from timertt::details::engine_common< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >
using thread_safety
 Indicator of thread-safety.
 
using timer_action
 Alias for Timer_Action.
 

Public Member Functions

 timer_list_engine ()
 Default constructor.
 
 timer_list_engine (Error_Logger error_logger, Actor_Exception_Handler exception_handler)
 Constructor with all parameters.
 
 ~timer_list_engine ()
 
timer_object_holder< Thread_Safety > allocate ()
 Create timer to be activated later.
 
template<class Duration_1 , class Duration_2 >
bool activate (timer_object_holder< Thread_Safety > timer, Duration_1 pause, Duration_2 period, timer_action action)
 Activate timer and schedule it for execution.
 
template<class Duration_1 , class Duration_2 >
bool reschedule (timer_object_holder< Thread_Safety > timer, Duration_1 pause, Duration_2 period, timer_action action)
 Perform an attempt to reschedule a timer.
 
void deactivate (timer_object_holder< Thread_Safety > timer)
 Deactivate timer and remove it from the list.
 
template<typename Unique_Lock >
void process_expired_timers (Unique_Lock &lock)
 Build sublist of elapsed timers and process them all.
 
bool empty () const
 Is empty timer list?
 
monotonic_clock::time_point nearest_time_point () const
 Get time point of the next timer.
 
void clear_all ()
 Deactivate all timers and cleanup internal data structures.
 
- Public Member Functions inherited from timertt::details::engine_common< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >
 engine_common (Error_Logger error_logger, Actor_Exception_Handler exception_handler)
 Initializing constructor.
 
timer_quantities get_timer_quantities () const
 Get the quantities of timers of various types.
 

Private Types

using base_type
 An alias for base class.
 

Private Member Functions

void insert_timer_to_list (timer_type *timer)
 Insert timer to the list.
 
void remove_timer_from_list (timer_type *timer)
 Remove the timer from the list.
 
timer_typemake_exec_list ()
 Build sublist of elapsed timers.
 
template<class Unique_Lock >
void exec_actions (Unique_Lock &lock, timer_type *head) TIMERTT_NOEXCEPT
 Execute all active timers in the sublist.
 
void utilize_exec_list (timer_type *head)
 Process list of elapsed timers after execution of its actions.
 

Static Private Member Functions

static void ensure_timer_deactivated (const timer_type *timer)
 Hard check for deactivation state of the timer.
 

Private Attributes

Object's attributes.
timer_typem_head = nullptr
 Head of the list of timers.
 
timer_typem_tail = nullptr
 Tail of the list of timers.
 

Additional Inherited Members

- Protected Member Functions inherited from timertt::details::engine_common< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >
void inc_timer_count (timer_kind kind)
 Helper method for increment the count of timers of the specific type.
 
void dec_timer_count (timer_kind kind)
 Helper method for decrement the count of timers of the specific type.
 
void reset_timer_count ()
 Helper method for reseting quantities of timers to zero.
 
- Protected Attributes inherited from timertt::details::engine_common< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >
Error_Logger m_error_logger
 Error logger.
 
Actor_Exception_Handler m_exception_handler
 Exception handler.
 
timer_quantities m_timer_quantities
 Quantities of timers of various types.
 

Detailed Description

template<typename Thread_Safety, typename Time_Action, typename Error_Logger, typename Actor_Exception_Handler>
class timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >

An engine for timer list mechanism.

This engine uses double-linked list of timers as timer mechanism. This list is ordered. The head of the list is the timer with the minimum time point.

When used with timer thread then the thread sleeps until the first timer in the list elapsed. Then thread build sublist of elapsed timers and process them. Single-shot timers are removed after processing. Periodic timers rescheduled (inserted into appropriate places in the list).

Note
After building sublist of elapsed timers thread unblocks object mutex and calls timer actors for timers from the sublist. And locks object back right after processing. It means that actors call call timer thread object. And there won't be frequent mutex locking/unlocking operations for building and processing sublist of elapsed timers. This allows to process millions of timer actor per second.
Attention
This type of timer thread is good for situations where there are many timers with equal pauses and repetition periods. In that cases almost all timers will be added to the end of the list. But if there are many timers with very different pauses then operation of activating and rescheduling of timers will be too expensive. Timer thread based on timer_wheel or timer_heap is more appropriate for that scenario.
Template Parameters
Thread_SafetyThread-safety indicator. Must be timertt::thread_safety::unsafe or timertt::thread_safety::safe.
Timer_Actiontype of functor to perform an user-defined action when timer expires. This must be Moveable and MoveConstructible type.
Error_Loggertype of logger for errors detected during timer thread execution. Interface for error logger is defined by default_error_logger class.
Actor_Exception_Handlertype of handler for dealing with exceptions thrown from timer actors. Interface for exception handler is defined by default_actor_exception_handler.

Definition at line 1651 of file 3rd_party/timertt/all.hpp.

Member Typedef Documentation

◆ base_type

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
using timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::base_type
private
Initial value:
Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >

An alias for base class.

Definition at line 1656 of file 3rd_party/timertt/all.hpp.

◆ defaults_type

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timer_list_engine_defaults timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::defaults_type

Type with default parameters for this engine.

Definition at line 1664 of file 3rd_party/timertt/all.hpp.

◆ scoped_timer_object

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
using timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::scoped_timer_object
Initial value:
scoped_timer_object_holder< timer_type >

Alias for scoped timer object.

Definition at line 1670 of file 3rd_party/timertt/all.hpp.

◆ timer_action

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
using timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::timer_action = typename base_type::timer_action

Alias for timer_action type.

Definition at line 1667 of file 3rd_party/timertt/all.hpp.

Constructor & Destructor Documentation

◆ timer_list_engine() [1/2]

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::timer_list_engine ( )
inline

Default constructor.

Definition at line 1674 of file 3rd_party/timertt/all.hpp.

◆ timer_list_engine() [2/2]

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::timer_list_engine ( Error_Logger error_logger,
Actor_Exception_Handler exception_handler )
inline

Constructor with all parameters.

Parameters
error_loggerAn error logger for timer thread.
exception_handlerAn actor exception handler for timer thread.

Definition at line 1681 of file 3rd_party/timertt/all.hpp.

◆ ~timer_list_engine()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::~timer_list_engine ( )
inline

Definition at line 1690 of file 3rd_party/timertt/all.hpp.

Member Function Documentation

◆ activate()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<class Duration_1 , class Duration_2 >
bool timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::activate ( timer_object_holder< Thread_Safety > timer,
Duration_1 pause,
Duration_2 period,
timer_action action )
inline

Activate timer and schedule it for execution.

Returns
true if the new timer is the first timer in the list.
Exceptions
std::exceptionIf timer thread is not started.
std::exceptionIf timer is already activated.
Template Parameters
Duration_1actual type which represents time duration.
Duration_2actual type which represents time duration.
Parameters
timerTimer to be activated.
pausePause for timer execution.
periodRepetition period. If Duration_2::zero() == period then timer will be single-shot.
actionAction for the timer.

Definition at line 1715 of file 3rd_party/timertt/all.hpp.

◆ allocate()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timer_object_holder< Thread_Safety > timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::allocate ( )
inline

Create timer to be activated later.

Definition at line 1697 of file 3rd_party/timertt/all.hpp.

◆ clear_all()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::clear_all ( )
inline

Deactivate all timers and cleanup internal data structures.

Definition at line 1912 of file 3rd_party/timertt/all.hpp.

◆ deactivate()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::deactivate ( timer_object_holder< Thread_Safety > timer)
inline

Deactivate timer and remove it from the list.

Parameters
timerTimer to be deactivated.

Definition at line 1837 of file 3rd_party/timertt/all.hpp.

◆ empty()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
bool timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::empty ( ) const
inline

Is empty timer list?

Returns
true if there is no more timers.

Definition at line 1892 of file 3rd_party/timertt/all.hpp.

◆ ensure_timer_deactivated()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
static void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::ensure_timer_deactivated ( const timer_type * timer)
inlinestaticprivate

Hard check for deactivation state of the timer.

Exceptions
std::runtimer_errorif timer is not deactivated.

Definition at line 1990 of file 3rd_party/timertt/all.hpp.

◆ exec_actions()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<class Unique_Lock >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::exec_actions ( Unique_Lock & lock,
timer_type * head )
inlineprivate

Execute all active timers in the sublist.

Object is unlocked and locked back after sublist processing.

Parameters
lockObject lock. This lock will be unlocked before execution of actions and locked back after.
headHead of execution list. Cannot be nullptr.

Definition at line 2118 of file 3rd_party/timertt/all.hpp.

◆ insert_timer_to_list()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::insert_timer_to_list ( timer_type * timer)
inlineprivate

Insert timer to the list.

Insertion starts from the tail of the list. And if timer has lower timer_type::m_whan value then the last list item there is an loop of searching appropriate place by going to the head of the list.

Doesn't increment reference count for timer.

Parameters
timerTimer to be inserted.

Definition at line 2006 of file 3rd_party/timertt/all.hpp.

◆ make_exec_list()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timer_type * timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::make_exec_list ( )
inlineprivate

Build sublist of elapsed timers.

All timers in the sublist receive timer_status::wait_for_execution status.

Definition at line 2073 of file 3rd_party/timertt/all.hpp.

◆ nearest_time_point()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
monotonic_clock::time_point timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::nearest_time_point ( ) const
inline

Get time point of the next timer.

Attention
Must be called only when !empty().

Definition at line 1903 of file 3rd_party/timertt/all.hpp.

◆ process_expired_timers()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<typename Unique_Lock >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::process_expired_timers ( Unique_Lock & lock)
inline

Build sublist of elapsed timers and process them all.

Object is unlocked and then locked back.

Parameters
lockObject's lock.

Definition at line 1872 of file 3rd_party/timertt/all.hpp.

◆ remove_timer_from_list()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::remove_timer_from_list ( timer_type * timer)
inlineprivate

Remove the timer from the list.

Doesn't decrement reference count for timer.

Definition at line 2052 of file 3rd_party/timertt/all.hpp.

◆ reschedule()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<class Duration_1 , class Duration_2 >
bool timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::reschedule ( timer_object_holder< Thread_Safety > timer,
Duration_1 pause,
Duration_2 period,
timer_action action )
inline

Perform an attempt to reschedule a timer.

Before v.1.2.1 there was just one way to reschedule a timer: method deactivate() must be called first and then method activate() must be called for the same timer. This approach is not fast because in the case of thread-safe engines it requires two operations on a mutex.

Since v.1.2.1 there is a reschedule() method which does deactivation of a timer (if it is active) and then new activation of this timer. All actions are performed by using just one operation on a mutex.

Note
This operation can fail if the timer to be rescheduled is in processing. Because of that it is recommended to use such operation for timer_managers only. But even with timer_managers this operation should be used with care.
Attention
It move operator for a timer_action throws then timer will be deactivated. The state for a timer_action itself will be unknown.
Exceptions
std::exceptionIf timer thread is not started.
std::exceptionIf timer is in processing right now.
Template Parameters
Duration_1actual type which represents time duration.
Duration_2actual type which represents time duration.
Since
v.1.2.1
Parameters
timerTimer to be rescheduled.
pausePause for timer execution.
periodRepetition period. If Duration_2::zero() == period then timer will be single-shot.
actionAction for the timer.

Definition at line 1782 of file 3rd_party/timertt/all.hpp.

◆ utilize_exec_list()

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
void timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::utilize_exec_list ( timer_type * head)
inlineprivate

Process list of elapsed timers after execution of its actions.

Active periodic timers will be rescheduled. All other timers will be deactivated and removed.

Parameters
headHead of execution list. Cannot be null.

Definition at line 2174 of file 3rd_party/timertt/all.hpp.

Member Data Documentation

◆ m_head

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timer_type* timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::m_head = nullptr
private

Head of the list of timers.

Definition at line 1976 of file 3rd_party/timertt/all.hpp.

◆ m_tail

template<typename Thread_Safety , typename Time_Action , typename Error_Logger , typename Actor_Exception_Handler >
timer_type* timertt::details::timer_list_engine< Thread_Safety, Time_Action, Error_Logger, Actor_Exception_Handler >::m_tail = nullptr
private

Tail of the list of timers.

Definition at line 1979 of file 3rd_party/timertt/all.hpp.


The documentation for this class was generated from the following file: