Fawkes API  Fawkes Development Version
fawkes::TimeWait Class Reference

Time wait utility. More...

#include <>>

Public Member Functions

 TimeWait (Clock *clock, long int desired_loop_time_usec)
 Constructor. More...
 
 ~TimeWait ()
 Destructor. More...
 
void mark_start ()
 Mark start of loop. More...
 
void wait ()
 Wait until minimum loop time has been reached. More...
 
void wait_systime ()
 Wait until minimum loop time has been reached in real time. More...
 

Static Public Member Functions

static void wait (long int usec)
 Wait at least usec microseconds. More...
 
static void wait_systime (long int usec)
 Wait at least usec microseconds. More...
 

Detailed Description

Time wait utility.

This class allows for guaranteed waiting for a specified amout of time. It can either be used to suspend the current thread for at least the given time (static methods) or it can be used to reach a desired minimum loop time. For this instantiate the class and call set_start() at the beginning of the loop and wait() at the end. wait() will then suspend the thread as long as needed to have the desired minimum loop time. The TimeWait utility will use the current clock time. Thus it may wait for a given amount of say simulated time.

Author
Tim Niemueller

Definition at line 32 of file wait.h.

Constructor & Destructor Documentation

◆ TimeWait()

fawkes::TimeWait::TimeWait ( Clock clock,
long int  desired_loop_time_usec 
)

Constructor.

Parameters
clockclock to use
desired_loop_time_usecdesired minimum loop time in microseconds

Definition at line 49 of file wait.cpp.

◆ ~TimeWait()

fawkes::TimeWait::~TimeWait ( )

Destructor.

Definition at line 60 of file wait.cpp.

Member Function Documentation

◆ mark_start()

◆ wait() [1/2]

◆ wait() [2/2]

void fawkes::TimeWait::wait ( long int  usec)
static

Wait at least usec microseconds.

Think of this as an uninterruptible usleep(). This method will not return before at least usec microseconds have passed. It may be longer but never less. Time is tracked in the current Clock time scale. This may be simulated time or real time. It is assumed that the (simulated time) is at worst slower, but never faster than real time. Thus 1 microsecond real time is at least 1 microsecond clock time.

Parameters
usecnumber of microseconds to wait at least

Definition at line 143 of file wait.cpp.

References fawkes::Clock::get_time(), fawkes::Clock::instance(), and fawkes::time_diff_usec().

◆ wait_systime() [1/2]

void fawkes::TimeWait::wait_systime ( )

Wait until minimum loop time has been reached in real time.

This uses the system time and not an external time source if defined.

Definition at line 100 of file wait.cpp.

References fawkes::Clock::get_systime().

Referenced by RosClockThread::loop(), RRDThread::loop(), ProcRRDThread::loop(), MongoRRDThread::loop(), BlackBoardSynchronizationThread::loop(), fawkes::FawkesMainThread::loop(), and fawkes::WebviewJpegStreamProducer::loop().

◆ wait_systime() [2/2]

void fawkes::TimeWait::wait_systime ( long int  usec)
static

Wait at least usec microseconds.

Think of this as an uninterruptible usleep(). This method will not return before at least usec microseconds have passed. It may be longer but never less. Time is tracked in system time scale (real time).

Parameters
usecnumber of microseconds to wait at least

Definition at line 122 of file wait.cpp.

References fawkes::time_diff_usec().


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