UCommon
ucommon::Timer Class Reference

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

#include <timers.h>

Inheritance diagram for ucommon::Timer:

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.
 
 operator bool () const
 Check if timer expired for is() expression.
 
bool operator! () const
 Check if timer has expired.
 
bool operator!= (const Timer &timer) const
 Compare timers if not same timeout.
 
timeout_t operator* () const
 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- (const Timer &timer)
 Compute difference between two timers.
 
Timeroperator-= (time_t expire)
 Adjust timer expiration.
 
Timeroperator-= (timeout_t expire)
 Adjust timer expiration.
 
bool operator< (const Timer &timer) const
 Compare timers if earlier timeout than another timer.
 
bool operator<= (const Timer &timer) const
 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== (const Timer &timer) const
 Compare timers if same timeout.
 
bool operator> (const Timer &timer) const
 Compare timers if later timeout than another timer.
 
bool operator>= (const Timer &timer) const
 Compare timers if later than or equal to another timer.
 
void set (time_t expire)
 Set the timer to expire.
 
void set (timeout_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 (const Timer &copy)
 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.
 

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 = ((timeout_t)(-1))
 
static const time_t reset = ((time_t)(0))
 

Protected Member Functions

bool is_active (void) const
 Check if timer active.
 
bool update (void)
 Check if timer has been updated since last check.
 

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 50 of file timers.h.

Member Typedef Documentation

◆ tick_t

typedef uint64_t ucommon::Timer::tick_t

Definition at line 86 of file timers.h.

Constructor & Destructor Documentation

◆ Timer() [1/3]

ucommon::Timer::Timer ( timeout_t offset)

Construct a triggered timer that expires at specified offset.

Parameters
offsetto expire in milliseconds.

◆ Timer() [2/3]

ucommon::Timer::Timer ( time_t offset)

Construct a triggered timer that expires at specified offset.

Parameters
offsetto expire in seconds.

◆ Timer() [3/3]

ucommon::Timer::Timer ( const Timer & copy)

Construct a timer from a copy of another timer.

Parameters
copyof timer to construct from.

Member Function Documentation

◆ get()

timeout_t ucommon::Timer::get ( void ) const

Get remaining time until the timer expires.

Returns
0 if expired or milliseconds still waiting.

◆ is_active()

bool ucommon::Timer::is_active ( void ) const
protected

Check if timer active.

Returns
true if active.

◆ operator bool()

ucommon::Timer::operator bool ( ) const

Check if timer expired for is() expression.

Returns
true if timer expired.

◆ operator!()

bool ucommon::Timer::operator! ( ) const

Check if timer has expired.

Returns
true if timer still pending.

◆ operator!=()

bool ucommon::Timer::operator!= ( const Timer & timer) const

Compare timers if not same timeout.

Parameters
timerto compare with.
Returns
true if not same.

◆ operator*()

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 144 of file timers.h.

◆ operator+=() [1/2]

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

Adjust timer expiration.

Parameters
expiretime to add in seconds.

◆ operator+=() [2/2]

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

Adjust timer expiration.

Parameters
expiretime to add in milliseconds.

◆ operator-()

timeout_t ucommon::Timer::operator- ( const Timer & timer)

Compute difference between two timers.

Parameters
timerto use for difference.
Returns
difference in milliseconds.

◆ operator-=() [1/2]

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

Adjust timer expiration.

Parameters
expiretime to subtract in seconds.

◆ operator-=() [2/2]

Timer & ucommon::Timer::operator-= ( timeout_t expire)

Adjust timer expiration.

Parameters
expiretime to subtract in milliseconds.

◆ operator<()

bool ucommon::Timer::operator< ( const Timer & timer) const

Compare timers if earlier timeout than another timer.

Parameters
timerto compare with.
Returns
true if earlier.

◆ operator<=()

bool ucommon::Timer::operator<= ( const Timer & timer) const

Compare timers if earlier than or equal to another timer.

Parameters
timerto compare with.
Returns
true if earlier or same.

◆ operator=() [1/2]

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

Set timer expiration.

Parameters
expiretimer in specified seconds.

◆ operator=() [2/2]

Timer & ucommon::Timer::operator= ( timeout_t expire)

Set timer expiration.

Parameters
expiretimer in milliseconds.

◆ operator==()

bool ucommon::Timer::operator== ( const Timer & timer) const

Compare timers if same timeout.

Parameters
timerto compare with.
Returns
true if same.

◆ operator>()

bool ucommon::Timer::operator> ( const Timer & timer) const

Compare timers if later timeout than another timer.

Parameters
timerto compare with.
Returns
true if later.

◆ operator>=()

bool ucommon::Timer::operator>= ( const Timer & timer) const

Compare timers if later than or equal to another timer.

Parameters
timerto compare with.
Returns
true if later or same.

◆ set() [1/2]

void ucommon::Timer::set ( time_t expire)

Set the timer to expire.

Parameters
expiretime in seconds.

◆ set() [2/2]

void ucommon::Timer::set ( timeout_t expire)

Set the timer to expire.

Parameters
expiretime in milliseconds.

◆ sync()

static void ucommon::Timer::sync ( Timer & timer)
static

Sleep current thread until the specified timer expires.

Parameters
timerto reference for sleep.

◆ ticks()

static tick_t ucommon::Timer::ticks ( void )
static

Get timer ticks since uuid epoch.

Returns
timer ticks in 100ns resolution.

◆ update()

bool ucommon::Timer::update ( void )
protected

Check if timer has been updated since last check.

This also sets updated false.

Returns
true if was updated.

Friends And Related Symbol Documentation

◆ Conditional

friend class Conditional
friend

Definition at line 53 of file timers.h.

◆ Event

friend class Event
friend

Definition at line 55 of file timers.h.

◆ Semaphore

friend class Semaphore
friend

Definition at line 54 of file timers.h.

Field Documentation

◆ inf

const timeout_t ucommon::Timer::inf = ((timeout_t)(-1))
static

Definition at line 80 of file timers.h.

◆ reset

const time_t ucommon::Timer::reset ( void ) = ((time_t)(0))
static

Definition at line 81 of file timers.h.


The documentation for this class was generated from the following file: