|
jaulib v1.4.0-2-g788cf73
Jau Support Library (C++, Java, ..)
|
A simple timer for timeout and interval applications, using one dedicated service_runner thread per instance. More...
#include <simple_timer.hpp>
Public Types | |
| typedef simple_timer & | Timer0_ref |
| typedef function< fraction_i64(Timer0_ref)> | Timer_func |
| User defined timer function using custom granularity via fraction_i64. | |
Public Member Functions | |
| simple_timer (const simple_timer &o)=delete | |
| No copy constructor nor move constructor. | |
| simple_timer (const std::string &name, const fraction_i64 &service_shutdown_timeout) noexcept | |
| Constructs a new service. | |
| bool | is_running () const noexcept |
| Returns true if timer is running. | |
| const std::string & | name () const noexcept |
| Return the given name of this timer. | |
| bool | shall_stop () const noexcept |
| Returns true if timer shall stop. | |
| bool | start (const fraction_i64 &duration_, Timer_func tofunc) noexcept |
| Start the timer with given user Timer_func function and initial duration. | |
| void | start_or_update (const fraction_i64 &duration_, Timer_func tofunc) noexcept |
| Start or update the timer with given user Timer_func function and initial duration. | |
| bool | stop () noexcept |
| Stop timer, see service_runner::stop() | |
| pthread_t | thread_id () const noexcept |
| Return the thread-id of this timer's worker thread, zero if not running. | |
A simple timer for timeout and interval applications, using one dedicated service_runner thread per instance.
Discussion: It is contemplated to add an implementation using a unique singleton service_runner for multiple timer instances via event loops.
Definition at line 52 of file simple_timer.hpp.
Definition at line 54 of file simple_timer.hpp.
User defined timer function using custom granularity via fraction_i64.
Function gets invoked for each timer event, i.e. after reaching the duration set earlier.
Definition at line 64 of file simple_timer.hpp.
|
noexcept |
Constructs a new service.
| name | thread name of this service |
| service_shutdown_timeout | maximum duration in fractions of seconds to wait for service to stop at stop(), where fractions_i64::zero waits infinitely |
Definition at line 61 of file simple_timer.cpp.
|
delete |
No copy constructor nor move constructor.
| o |
|
inlinenoexcept |
Return the given name of this timer.
Definition at line 92 of file simple_timer.hpp.
|
inlinenoexcept |
Return the thread-id of this timer's worker thread, zero if not running.
Definition at line 97 of file simple_timer.hpp.
|
inlinenoexcept |
Returns true if timer is running.
Definition at line 102 of file simple_timer.hpp.
|
inlinenoexcept |
Returns true if timer shall stop.
This flag can be used by the Timer_func function to determine whether to skip lengthly tasks.
Definition at line 109 of file simple_timer.hpp.
|
noexcept |
Start the timer with given user Timer_func function and initial duration.
| duration_ | initial timer duration in fractions of seconds until next timer event |
| tofunc | user Timer_func to be called on next timer event |
Definition at line 66 of file simple_timer.cpp.
|
noexcept |
Start or update the timer with given user Timer_func function and initial duration.
This is faster than calling stop() and start(), however, an already started timer user Timer_func will proceed.
| duration_ | initial timer duration in fractions of seconds until next timer event |
| tofunc | user Timer_func to be called on next timer event |
Definition at line 76 of file simple_timer.cpp.
|
inlinenoexcept |
Stop timer, see service_runner::stop()
Definition at line 136 of file simple_timer.hpp.