Timer_t Class Reference

#include <UTTimer.h>

Inheritance diagram for Timer_t:
BTreeNode_t< Timer_t, ustime_t >

List of all members.

Public Member Functions

 Timer_t (bool accept_jitter=false)
 ~Timer_t ()
void StartOneShot (ustime_t expires_at, const MessageDestination_t< TimerExpiredMessage_t > &dest, TimerManager_t *manager)
void StartPeriodic (uint32 period_ms, const MessageDestination_t< TimerExpiredMessage_t > &dest, TimerManager_t *manager)
void Cancel ()

Detailed Description

Timer class which sends a message to the target message destination when the timer expires. Timers can be periodic or one-shot. Timers must be added to a TimerManager_t object, which serves two functions: multiplexing multiple one-shot timers onto a single system timer, and protecting against race conditions in canceling a timer when a timer expired message may have been queued but not yet received. Timer expiration messages are sent synchronously, so the destination must be in a task installed in the same message loop as the timer manager. Timers have inherent, platform-specific resolution limits to what rate they can sustain. Those rates are:

        Windows: 25 ms
        Linux: 3 ms (even with two tests under valgrind)
        MacOS: 75 ms
    

These values are defined by the c_os_timer_reliable_ms constant, which is in milliseconds. The values are set such that even with four unit tests running similtaneously (basically, a heavily loaded system), an acceptable majority of timer expiration events will arrive on time. If it is acceptable for there to be some jitter under heavy load, the timer can be created to accept a time under the jitter limit. In that case, the absolute minimum must be respected:

        Windows: 10 ms
        Linux: 1 ms
        MacOS: 1 ms
    

These values are defined by the c_os_timer_resolution_ms constant, which is in milliseconds.

Definition at line 45 of file UTTimer.h.


Constructor & Destructor Documentation

Timer_t::Timer_t ( bool  accept_jitter = false  )  [inline]

Constructor.

Definition at line 224 of file UTTimer.h.

Timer_t::~Timer_t (  )  [inline]

Destructor.

Definition at line 232 of file UTTimer.h.


Member Function Documentation

void Timer_t::StartOneShot ( ustime_t  expires_at,
const MessageDestination_t< TimerExpiredMessage_t > &  dest,
TimerManager_t manager 
)

Starts a one-shot timer, which will be installed into the specified manager and will expire at the specified time, which is in the value space used by the system_time_us function. When that occurs, a message will be sent to the specified destination indicating that the timer has expired. When the timer expires, this timer will have been implicitly cancelled. The destination of the expiration message must be in the same message loop as the manager. If the timer was already started, it will be canceled and reset. If the time from now until the timer is expected to expire is under the platform minimum resolution as defined by c_os_timer_resolution_ms, the function will fail, but under most circumstances (basically, if you get lucky), the timer will be late.

void Timer_t::StartPeriodic ( uint32  period_ms,
const MessageDestination_t< TimerExpiredMessage_t > &  dest,
TimerManager_t manager 
)

Starts a periodic timer, which will send a message periodically as specified by period_ms. The destination of the expiration message must be in the same message loop as the manager. If the timer was already started, it will be canceled and reset. The period must be at least c_os_timer_resolution_ms.

void Timer_t::Cancel (  ) 

Cancels the timer. It is safe to cancel a timer any time, even if it was already canceled either implicitly or explicitly.


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

Generated on Tue Dec 14 22:35:07 2010 for UT library by  doxygen 1.6.1