All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::SleepSync Class Reference

Synchronized sleeping. More...

#include <Radiant/Sleep.hpp>

Public Member Functions

void resetTiming ()
 Resets the reference time to current time.
 
 SleepSync ()
 The constructor resets the timing.
 
void sleepSynchroUs (long us)
 Sleep for n microseconds. More...
 

Detailed Description

Synchronized sleeping.

This class can be used to execute a piece of code in fixed intervals. Here's a simple example where a loop cycle is executed every 100ms:

const long loopCycleUs = 100*1000;//100ms
while (true) {
sleep.resetTiming();
// do something that differs in length between [0..loopCycleUs]
// ...
sleep.sleepSynchroUs(loopCycleUs);
}

Member Function Documentation

void Radiant::SleepSync::sleepSynchroUs ( long  us)

Sleep for n microseconds.

This function calculates how much time has passed since the

last sleep and sleeps to fulfill the required time period.

Parameters
usmicroseconds to sleep