UCommon
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends
ucommon::Timer Class Reference

Timer class to use when scheduling realtime events. More...

#include <timers.h>

Inheritance diagram for ucommon::Timer:
Inheritance graph
[legend]

Public Types

typedef uint64_t tick_t

Public Member Functions

void clear (void)
 Clear pending timer, has no value.
timeout_t get (void)
 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 ()
 Check if timer expired for is() expression.
bool operator! ()
 Check if timer has expired.
bool operator!= (Timer &timer)
 Compare timers if not same timeout.
timeout_t operator* ()
 Get remaining time until timer expires by reference.
Timeroperator+= (time_t expire)
 Adjust timer expiration.
Timeroperator+= (timeout_t expire)
 Adjust timer expiration.
timeout_t operator- (Timer &timer)
 Compute difference between two timers.
Timeroperator-= (time_t expire)
 Adjust timer expiration.
Timeroperator-= (timeout_t expire)
 Adjust timer expiration.
bool operator< (Timer &timer)
 Compare timers if earlier timeout than another timer.
bool operator<= (Timer &timer)
 Compare timers if earlier than or equal to another timer.
Timeroperator= (time_t expire)
 Set timer expiration.
Timeroperator= (timeout_t expire)
 Set timer expiration.
bool operator== (Timer &timer)
 Compare timers if same timeout.
bool operator> (Timer &timer)
 Compare timers if later timeout than another timer.
bool operator>= (Timer &timer)
 Compare timers if later than or equal to another timer.
void set (timeout_t expire)
 Set the timer to expire.
void set (time_t expire)
 Set the timer to expire.
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.
 Timer (time_t offset)
 Construct a triggered timer that expires at specified offset.
 Timer (Timer &copy)
 Construct a timer from a copy of another timer.

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 timeout_t inf
 A value to use for infinite time.
static 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 49 of file timers.h.


Constructor & Destructor Documentation

ucommon::Timer::Timer ( timeout_t  offset)

Construct a triggered timer that expires at specified offset.

Parameters:
offsetto expire in milliseconds.
ucommon::Timer::Timer ( time_t  offset)

Construct a triggered timer that expires at specified offset.

Parameters:
offsetto expire in seconds.
ucommon::Timer::Timer ( Timer copy)

Construct a timer from a copy of another timer.

Parameters:
copyof timer to construct from.

Member Function Documentation

timeout_t ucommon::Timer::get ( void  )

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  )

Check if timer expired.

Returns:
true if expired.

Reimplemented in ucommon::TimerQueue::event.

bool ucommon::Timer::isUpdated ( void  )

Check if timer has been updated since last check.

Returns:
true if updated.
ucommon::Timer::operator bool ( )

Check if timer expired for is() expression.

Returns:
true if timer expired.
bool ucommon::Timer::operator! ( )

Check if timer has expired.

Returns:
true if timer still pending.
bool ucommon::Timer::operator!= ( Timer timer)

Compare timers if not same timeout.

Parameters:
timerto compare with.
Returns:
true if not same.
timeout_t ucommon::Timer::operator* ( )
inline

Get remaining time until timer expires by reference.

Returns:
0 if expired or milliseconds still waiting.

Definition at line 146 of file timers.h.

Timer& ucommon::Timer::operator+= ( time_t  expire)

Adjust timer expiration.

Parameters:
expiretime to add in seconds.
Timer& ucommon::Timer::operator+= ( timeout_t  expire)

Adjust timer expiration.

Parameters:
expiretime to add in milliseconds.
timeout_t ucommon::Timer::operator- ( Timer timer)

Compute difference between two timers.

Parameters:
timerto use for difference.
Returns:
difference in milliseconds.
Timer& ucommon::Timer::operator-= ( time_t  expire)

Adjust timer expiration.

Parameters:
expiretime to subtract in seconds.
Timer& ucommon::Timer::operator-= ( timeout_t  expire)

Adjust timer expiration.

Parameters:
expiretime to subtract in milliseconds.
bool ucommon::Timer::operator< ( Timer timer)

Compare timers if earlier timeout than another timer.

Parameters:
timerto compare with.
Returns:
true if earlier.
bool ucommon::Timer::operator<= ( Timer timer)

Compare timers if earlier than or equal to another timer.

Parameters:
timerto compare with.
Returns:
true if earlier or same.
Timer& ucommon::Timer::operator= ( time_t  expire)

Set timer expiration.

Parameters:
expiretimer in specified seconds.
Timer& ucommon::Timer::operator= ( timeout_t  expire)

Set timer expiration.

Parameters:
expiretimer in milliseconds.
bool ucommon::Timer::operator== ( Timer timer)

Compare timers if same timeout.

Parameters:
timerto compare with.
Returns:
true if same.
bool ucommon::Timer::operator> ( Timer timer)

Compare timers if later timeout than another timer.

Parameters:
timerto compare with.
Returns:
true if later.
bool ucommon::Timer::operator>= ( Timer timer)

Compare timers if later than or equal to another timer.

Parameters:
timerto compare with.
Returns:
true if later or same.
void ucommon::Timer::set ( timeout_t  expire)

Set the timer to expire.

Parameters:
expiretime in milliseconds.
void ucommon::Timer::set ( time_t  expire)

Set the timer to expire.

Parameters:
expiretime in seconds.
static void ucommon::Timer::sync ( Timer timer)
static

Sleep current thread until the specified timer expires.

Parameters:
timerto 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: