CARMA C++
carma::util::PeriodicTimer Class Reference

Timer object that fires at a fixed rate. More...

#include <carma/util/PeriodicTimer.h>

Inheritance diagram for carma::util::PeriodicTimer:
carma::util::ScheduledTimer

Public Member Functions

 PeriodicTimer (const struct::timespec &period, bool preflight=true)
 Construct an instance with the given period. More...
 
 PeriodicTimer (const struct::timeval &period, bool preflight=true)
 Same as PeriodicTimer( const struct ::timespec &, bool ) except this constructor takes a struct ::timeval for the period parameter. More...
 
void ResetNextFireAbsoluteTime (const struct::timespec &nextFireAbsoluteTime)
 Reset the next fire time (and by association the entire queue of fire times) for this instance. More...
 
void ResetNextFireAbsoluteTime (const struct::timeval &nextFireAbsoluteTime)
 Same as ResetNextFireAbsoluteTime( const struct ::timespec & ) except that this method takes a struct ::timeval for the nextFireAbsoluteTime parameter. More...
 
void ResetNextFireAbsoluteTimeAndWait (const struct::timespec &nextFireAbsoluteTime)
 Same as ResetNextFireAbsoluteTime( const struct ::timespec & ) except that this method also waits for the new next fire time to arrive before returning the new next fire time that it has just waited for. More...
 
void ResetNextFireAbsoluteTimeAndWait (const struct::timeval &nextFireAbsoluteTime)
 Same as ResetNextFireAbsoluteTimeAndWait( const struct ::timespec & ) except that this method takes a struct ::timeval for the nextFireAbsoluteTime parameter. More...
 
- Public Member Functions inherited from carma::util::ScheduledTimer
void InterruptPresentOrNextWait ()
 Interrupt the wait that is presently occurring on this timer object or if no such wait is presently occurring then preemptively interrupt the next wait that occurs. More...
 
void WaitForNextFireTime ()
 Block (the thread of the caller) until the next fire time for the timer arrives. More...
 

Protected Member Functions

virtual struct::timespec CalculateNextFireAbsoluteTime (const struct::timespec &fireAbsoluteTime)
 
- Protected Member Functions inherited from carma::util::ScheduledTimer
void refreshNextFireAbsTimeIfNeeded (Timespec *nextFireAbsTime)
 
 ScheduledTimer (bool preflight)
 
void SetNextFireTime (const Timespec &nextFireAbsTime)
 
void SetNextFireTimeAndWait (const Timespec &nextFireAbsTime)
 

Additional Inherited Members

- Protected Types inherited from carma::util::ScheduledTimer
typedef struct::timespec Timespec
 
- Static Protected Member Functions inherited from carma::util::ScheduledTimer
static void sanityCheckTimespec (const Timespec &ts)
 

Detailed Description

Timer object that fires at a fixed rate.

Warning
An instance is NOT ready to wait on simply by being constructed. You MUST reset an instance's next fire time before (or at the same time as) the first wait on an instance.
Note
If you want a timer that fires at a fixed offset after every Nth CARMA frame time then consider using an instance of FrameAlignedTimer instead.

Definition at line 23 of file PeriodicTimer.h.

Constructor & Destructor Documentation

carma::util::PeriodicTimer::PeriodicTimer ( const struct::timespec &  period,
bool  preflight = true 
)
explicit

Construct an instance with the given period.

If any parameters are invalid or an internal error occurs then an exception will be thrown.

Parameters
periodHow often in absolute time this instance will fire. The value must be greater than 0.
preflightIf true then the instance will be preflighted as part of construction. Preflighting involves actually performing a very quick wait and/or test on the internal primitives used to implement the instance. This MAY reduce any increased one-time latency and/or drift in the first wait on the instance (on some operating systems).
Precondition
period is greater than 0.
carma::util::PeriodicTimer::PeriodicTimer ( const struct::timeval &  period,
bool  preflight = true 
)
explicit

Same as PeriodicTimer( const struct ::timespec &, bool ) except this constructor takes a struct ::timeval for the period parameter.

Member Function Documentation

void carma::util::PeriodicTimer::ResetNextFireAbsoluteTime ( const struct::timespec &  nextFireAbsoluteTime)

Reset the next fire time (and by association the entire queue of fire times) for this instance.

All old fire times for this instance are removed from the queue as though they never existed.

Parameters
nextFireAbsoluteTimeabsolute time for the new next fire time for this instance.
void carma::util::PeriodicTimer::ResetNextFireAbsoluteTime ( const struct::timeval &  nextFireAbsoluteTime)

Same as ResetNextFireAbsoluteTime( const struct ::timespec & ) except that this method takes a struct ::timeval for the nextFireAbsoluteTime parameter.

void carma::util::PeriodicTimer::ResetNextFireAbsoluteTimeAndWait ( const struct::timespec &  nextFireAbsoluteTime)

Same as ResetNextFireAbsoluteTime( const struct ::timespec & ) except that this method also waits for the new next fire time to arrive before returning the new next fire time that it has just waited for.

Postcondition
Either absolute time is greater than or equal to the fire time returned or an exception has been thrown.
void carma::util::PeriodicTimer::ResetNextFireAbsoluteTimeAndWait ( const struct::timeval &  nextFireAbsoluteTime)

Same as ResetNextFireAbsoluteTimeAndWait( const struct ::timespec & ) except that this method takes a struct ::timeval for the nextFireAbsoluteTime parameter.


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