ucommon::Timer Class Reference
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.
|
bool | isExpired (void) |
| Check if timer expired.
|
bool | isUpdated (void) |
| Check if timer has been updated since last check.
|
| operator bool () const |
| Check if timer expired for is() expression.
|
bool | operator! () const |
| Check if timer has expired.
|
bool | operator!= (const Timer &timer) |
| Compare timers if not same timeout.
|
timeout_t | operator* () const |
| Get remaining time until timer expires by reference.
|
Timer & | operator+= (timeout_t expire) |
| Adjust timer expiration.
|
Timer & | operator+= (time_t expire) |
| Adjust timer expiration.
|
timeout_t | operator- (const Timer &timer) |
| Compute difference between two timers.
|
Timer & | operator-= (timeout_t expire) |
| Adjust timer expiration.
|
Timer & | operator-= (time_t expire) |
| Adjust timer expiration.
|
bool | operator< (const Timer &timer) |
| Compare timers if earlier timeout than another timer.
|
bool | operator<= (const Timer &timer) |
| Compare timers if earlier than or equal to another timer.
|
Timer & | operator= (timeout_t expire) |
| Set timer expiration.
|
Timer & | operator= (time_t expire) |
| Set timer expiration.
|
bool | operator== (const Timer &timer) |
| Compare timers if same timeout.
|
bool | operator> (const Timer &timer) |
| Compare timers if later timeout than another timer.
|
bool | operator>= (const Timer &timer) |
| Compare timers if later than or equal to another timer.
|
void | set (void) |
| Set (update) the timer with current time.
|
void | set (time_t expire) |
| Set the timer to expire.
|
void | set (timeout_t expire) |
| Set the timer to expire.
|
| Timer (const Timer ©) |
| Construct a timer from a copy of another timer.
|
| Timer (time_t offset) |
| Construct a triggered timer that expires at specified offset.
|
| Timer (timeout_t offset) |
| Construct a triggered timer that expires at specified offset.
|
| Timer () |
| Construct an untriggered timer set to the time of creation.
|
Static Public Member Functions |
static void | sync (Timer &timer) |
| Sleep current thread until the specified timer expires.
|
static tick_t | ticks (void) |
| Get timer ticks since uuid epoch.
|
Static Public Attributes |
static const timeout_t | inf |
| A value to use for infinite time.
|
static const time_t | reset |
| A value to use when resetting.
|
Friends |
class | Conditional |
class | Event |
class | Semaphore |
Detailed Description
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.
Definition at line 45 of file timers.h.
Constructor & Destructor Documentation
Construct a triggered timer that expires at specified offset.
- Parameters:
-
| offset | to expire in milliseconds. |
ucommon::Timer::Timer |
( |
time_t |
offset |
) |
|
Construct a triggered timer that expires at specified offset.
- Parameters:
-
| offset | to expire in seconds. |
ucommon::Timer::Timer |
( |
const Timer & |
copy |
) |
|
Construct a timer from a copy of another timer.
- Parameters:
-
| copy | of timer to construct from. |
Member Function Documentation
Get remaining time until the timer expires.
- Returns:
- 0 if expired or milliseconds still waiting.
Reimplemented in ucommon::TimerQueue::event.
bool ucommon::Timer::isExpired |
( |
void |
|
) |
|
bool ucommon::Timer::isUpdated |
( |
void |
|
) |
|
Check if timer has been updated since last check.
- Returns:
- true if updated.
ucommon::Timer::operator bool |
( |
|
) |
const |
Check if timer expired for is() expression.
- Returns:
- true if timer expired.
bool ucommon::Timer::operator! |
( |
|
) |
const |
Check if timer has expired.
- Returns:
- true if timer still pending.
bool ucommon::Timer::operator!= |
( |
const Timer & |
timer |
) |
|
Compare timers if not same timeout.
- Parameters:
-
- Returns:
- true if not same.
timeout_t ucommon::Timer::operator* |
( |
|
) |
const [inline] |
Get remaining time until timer expires by reference.
- Returns:
- 0 if expired or milliseconds still waiting.
Definition at line 133 of file timers.h.
Adjust timer expiration.
- Parameters:
-
| expire | time to add in milliseconds. |
Timer& ucommon::Timer::operator+= |
( |
time_t |
expire |
) |
|
Adjust timer expiration.
- Parameters:
-
| expire | time to add in seconds. |
Compute difference between two timers.
- Parameters:
-
| timer | to use for difference. |
- Returns:
- difference in milliseconds.
Adjust timer expiration.
- Parameters:
-
| expire | time to subtract in milliseconds. |
Timer& ucommon::Timer::operator-= |
( |
time_t |
expire |
) |
|
Adjust timer expiration.
- Parameters:
-
| expire | time to subtract in seconds. |
bool ucommon::Timer::operator< |
( |
const Timer & |
timer |
) |
|
Compare timers if earlier timeout than another timer.
- Parameters:
-
- Returns:
- true if earlier.
bool ucommon::Timer::operator<= |
( |
const Timer & |
timer |
) |
|
Compare timers if earlier than or equal to another timer.
- Parameters:
-
- Returns:
- true if earlier or same.
Set timer expiration.
- Parameters:
-
| expire | timer in milliseconds. |
Timer& ucommon::Timer::operator= |
( |
time_t |
expire |
) |
|
Set timer expiration.
- Parameters:
-
| expire | timer in specified seconds. |
bool ucommon::Timer::operator== |
( |
const Timer & |
timer |
) |
|
Compare timers if same timeout.
- Parameters:
-
- Returns:
- true if same.
bool ucommon::Timer::operator> |
( |
const Timer & |
timer |
) |
|
Compare timers if later timeout than another timer.
- Parameters:
-
- Returns:
- true if later.
bool ucommon::Timer::operator>= |
( |
const Timer & |
timer |
) |
|
Compare timers if later than or equal to another timer.
- Parameters:
-
- Returns:
- true if later or same.
void ucommon::Timer::set |
( |
time_t |
expire |
) |
|
Set the timer to expire.
- Parameters:
-
void ucommon::Timer::set |
( |
timeout_t |
expire |
) |
|
Set the timer to expire.
- Parameters:
-
| expire | time in milliseconds. |
static void ucommon::Timer::sync |
( |
Timer & |
timer |
) |
[static] |
Sleep current thread until the specified timer expires.
- Parameters:
-
| timer | to reference for sleep. |
static tick_t ucommon::Timer::ticks |
( |
void |
|
) |
[static] |
Get timer ticks since uuid epoch.
- Returns:
- timer ticks in 100ns resolution.
The documentation for this class was generated from the following file: