UCommon
|
Timer class to use when scheduling realtime events. More...
#include <timers.h>
Public Types | |
typedef uint64_t | tick_t |
Public Member Functions | |
void | clear (void) |
Clear pending timer, has no value. | |
timeout_t | get (void) const |
Get remaining time until the timer expires. More... | |
timeout_t | operator * () const |
Get remaining time until timer expires by reference. More... | |
operator bool () const | |
Check if timer expired for is() expression. More... | |
bool | operator! () const |
Check if timer has expired. More... | |
bool | operator!= (const Timer &timer) const |
Compare timers if not same timeout. More... | |
Timer & | operator+= (time_t expire) |
Adjust timer expiration. More... | |
Timer & | operator+= (timeout_t expire) |
Adjust timer expiration. More... | |
timeout_t | operator- (const Timer &timer) |
Compute difference between two timers. More... | |
Timer & | operator-= (time_t expire) |
Adjust timer expiration. More... | |
Timer & | operator-= (timeout_t expire) |
Adjust timer expiration. More... | |
bool | operator< (const Timer &timer) const |
Compare timers if earlier timeout than another timer. More... | |
bool | operator<= (const Timer &timer) const |
Compare timers if earlier than or equal to another timer. More... | |
Timer & | operator= (time_t expire) |
Set timer expiration. More... | |
Timer & | operator= (timeout_t expire) |
Set timer expiration. More... | |
bool | operator== (const Timer &timer) const |
Compare timers if same timeout. More... | |
bool | operator> (const Timer &timer) const |
Compare timers if later timeout than another timer. More... | |
bool | operator>= (const Timer &timer) const |
Compare timers if later than or equal to another timer. More... | |
void | set (timeout_t expire) |
Set the timer to expire. More... | |
void | set (time_t expire) |
Set the timer to expire. More... | |
void | set (void) |
Set (update) the timer with current time. | |
Timer () | |
Construct an untriggered timer set to the time of creation. | |
Timer (timeout_t offset) | |
Construct a triggered timer that expires at specified offset. More... | |
Timer (time_t offset) | |
Construct a triggered timer that expires at specified offset. More... | |
Timer (const Timer ©) | |
Construct a timer from a copy of another timer. More... | |
Static Public Member Functions | |
static void | sync (Timer &timer) |
Sleep current thread until the specified timer expires. More... | |
static tick_t | ticks (void) |
Get timer ticks since uuid epoch. More... | |
Static Public Attributes | |
static const timeout_t | inf = ((timeout_t)(-1)) |
static const time_t | reset = ((time_t)(0)) |
Protected Member Functions | |
bool | is_active (void) const |
Check if timer active. More... | |
bool | update (void) |
Check if timer has been updated since last check. More... | |
Friends | |
class | Conditional |
class | Event |
class | Semaphore |
Timer class to use when scheduling realtime events.
The timer generally uses millisecond values but has a microsecond accuracy. On platforms that support it, the timer uses posix realtime monotonic clock extensions, otherwise lower accuracy timer systems might be used.
ucommon::Timer::Timer | ( | timeout_t | offset | ) |
Construct a triggered timer that expires at specified offset.
offset | to expire in milliseconds. |
ucommon::Timer::Timer | ( | time_t | offset | ) |
Construct a triggered timer that expires at specified offset.
offset | to expire in seconds. |
ucommon::Timer::Timer | ( | const Timer & | copy | ) |
Construct a timer from a copy of another timer.
copy | of timer to construct from. |
timeout_t ucommon::Timer::get | ( | void | ) | const |
Get remaining time until the timer expires.
|
protected |
Check if timer active.
|
inline |
ucommon::Timer::operator bool | ( | ) | const |
Check if timer expired for is() expression.
bool ucommon::Timer::operator! | ( | ) | const |
Check if timer has expired.
bool ucommon::Timer::operator!= | ( | const Timer & | timer | ) | const |
Compare timers if not same timeout.
timer | to compare with. |
Timer& ucommon::Timer::operator+= | ( | time_t | expire | ) |
Adjust timer expiration.
expire | time to add in seconds. |
Timer& ucommon::Timer::operator+= | ( | timeout_t | expire | ) |
Adjust timer expiration.
expire | time to add in milliseconds. |
timeout_t ucommon::Timer::operator- | ( | const Timer & | timer | ) |
Compute difference between two timers.
timer | to use for difference. |
Timer& ucommon::Timer::operator-= | ( | time_t | expire | ) |
Adjust timer expiration.
expire | time to subtract in seconds. |
Timer& ucommon::Timer::operator-= | ( | timeout_t | expire | ) |
Adjust timer expiration.
expire | time to subtract in milliseconds. |
bool ucommon::Timer::operator< | ( | const Timer & | timer | ) | const |
Compare timers if earlier timeout than another timer.
timer | to compare with. |
bool ucommon::Timer::operator<= | ( | const Timer & | timer | ) | const |
Compare timers if earlier than or equal to another timer.
timer | to compare with. |
Timer& ucommon::Timer::operator= | ( | time_t | expire | ) |
Set timer expiration.
expire | timer in specified seconds. |
Timer& ucommon::Timer::operator= | ( | timeout_t | expire | ) |
Set timer expiration.
expire | timer in milliseconds. |
bool ucommon::Timer::operator== | ( | const Timer & | timer | ) | const |
Compare timers if same timeout.
timer | to compare with. |
bool ucommon::Timer::operator> | ( | const Timer & | timer | ) | const |
Compare timers if later timeout than another timer.
timer | to compare with. |
bool ucommon::Timer::operator>= | ( | const Timer & | timer | ) | const |
Compare timers if later than or equal to another timer.
timer | to compare with. |
void ucommon::Timer::set | ( | timeout_t | expire | ) |
Set the timer to expire.
expire | time in milliseconds. |
void ucommon::Timer::set | ( | time_t | expire | ) |
Set the timer to expire.
expire | time in seconds. |
|
static |
Sleep current thread until the specified timer expires.
timer | to reference for sleep. |
|
static |
Get timer ticks since uuid epoch.
|
protected |
Check if timer has been updated since last check.
This also sets updated false.