|
| timer_heap_engine (std::size_t initial_heap_capacity, Error_Logger error_logger, Actor_Exception_Handler exception_handler) |
| Constructor with all parameters.
|
|
| ~timer_heap_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) |
| Process all expired timers from the heap.
|
|
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 () |
| Clear all timer demands.
|
|
| 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.
|
|
template<typename Thread_Safety, typename Timer_Action, typename Error_Logger, typename Actor_Exception_Handler>
class timertt::details::timer_heap_engine< Thread_Safety, Timer_Action, Error_Logger, Actor_Exception_Handler >
An engine for timer heap mechanism.
This timer engine uses timer mechanism based on heap data structure. The timer with the earlier time point is on the top of the heap. When this timer elapsed and removed next timer with the eralier time point is going to the top of the heap.
This implementation uses array-based binary heap. The array is growing as necessary to hold all the timers. The initial size of that array can be specified in the constructor.
- Note
- Unlike timer_wheel and timer_list threads this thread unlock and lock its mutex for processing every timers. It means that processing speed of this thread will be slower then for timer_wheel or timer_list threads. But this type of thread doesn't consume resources when there is no timers (unlike timer_wheel thread). And has very efficient activation and deactivation procedures (unlike timer_list thread).
- Template Parameters
-
Thread_Safety | Thread-safety indicator. Must be timertt::thread_safety::unsafe or timertt::thread_safety::safe. |
Timer_Action | type of functor to perform an user-defined action when timer expires. This must be Moveable and MoveConstructible type. |
Error_Logger | type of logger for errors detected during timer thread execution. Interface for error logger is defined by default_error_logger class. |
Actor_Exception_Handler | type of handler for dealing with exceptions thrown from timer actors. Interface for exception handler is defined by default_actor_exception_handler. |
Definition at line 2267 of file 3rd_party/timertt/all.hpp.
template<typename Thread_Safety , typename Timer_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<class Duration_1 , class Duration_2 >
Activate timer and schedule it for execution.
- Returns
- true is new timer is a timer on the top of the heap (has earlier expiration time).
- Exceptions
-
std::exception | If timer thread is not started. |
std::exception | If timer is already activated. |
- Template Parameters
-
Duration_1 | actual type which represents time duration. |
Duration_2 | actual type which represents time duration. |
- Parameters
-
timer | Timer to be activated. |
pause | Pause for timer execution. |
period | Repetition period. If Duration_2::zero() == period then timer will be single-shot. |
action | Action for the timer. |
Definition at line 2327 of file 3rd_party/timertt/all.hpp.
template<typename Thread_Safety , typename Timer_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<class Unique_Lock >
Execute the current timer.
- Parameters
-
lock | Object lock. This lock will be unlocked before execution of actions and locked back after. |
Definition at line 2660 of file 3rd_party/timertt/all.hpp.
template<typename Thread_Safety , typename Timer_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<typename Unique_Lock >
Process all expired timers from the heap.
- Note
- time_point for timers expiration detection is got only once at the begining on the method.
-
lock unlocked and then locked back for every timer action execution.
- Parameters
-
Definition at line 2498 of file 3rd_party/timertt/all.hpp.
template<typename Thread_Safety , typename Timer_Action , typename Error_Logger , typename Actor_Exception_Handler >
template<class Duration_1 , class Duration_2 >
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::exception | If timer thread is not started. |
std::exception | If timer is in processing right now. |
- Template Parameters
-
Duration_1 | actual type which represents time duration. |
Duration_2 | actual type which represents time duration. |
- Since
- v.1.2.1
- Parameters
-
timer | Timer to be rescheduled. |
pause | Pause for timer execution. |
period | Repetition period. If Duration_2::zero() == period then timer will be single-shot. |
action | Action for the timer. |
Definition at line 2395 of file 3rd_party/timertt/all.hpp.