Class CDynamicSleeper#

Class Documentation#

class CDynamicSleeper#

A class that is capable of sleeping the (approximately) correct amount of time while the rate of time is changing.

Public Functions

inline CDynamicSleeper()#

Creates an instance with a rate of 1.

The rate is the relative speed of time based on the system time.

inline void sleepFor(long long durationNsecs_)#

Blocks for the given amount of nanoseconds.

How long the function actually blocks depends on the current rate at which the time is supposed to run

Parameters:

durationNsecs_ – the duration in nanoseconds

inline void sleepUntil(long long sleepUntilTimeNsecs_)#

Blocks until the given point in sim time is reached.

How long the function actually blocks depends on the current rate at which the time is supposed to run

Parameters:

sleepUntilTimeNsecs_ – the simulation time in nanoseconds

inline void setRate(double rate_)#

sets the rate at which the time is supposed to run.

All threads that are waiting in the sleep function will automatically adjust their actual time to sleep based on the new rate.

Parameters:

rate_ – the rate of time relative to the system time

inline void setTime(long long nsecs_)#

Sets the sim time to the given value.

If the given time is lower than the time that was given the last time or lower than the time that was computed the last time the rate was changed, all waiting threads will abort waiting and return.

Parameters:

nsecs_ – the new simulation time in nanoseconds

inline void setTimeAndRate(long long time_nsecs_, double rate_)#

Sets the sim time and the rate of time to the given values.

If the given time is lower than the time that was given the last time or lower than the time that was computed the last time the rate was changed, all waiting threads will abort waiting and return.

Parameters:
  • time_nsecs_ – the new simulatoin time in nanoseconds

  • rate_ – the rate of the simulation time relative to the system clock

inline long long getCurrentInternalSimTime()#

getter for the internal simulation time used for computing how long to sleep

Returns:

the current simulation time

inline ~CDynamicSleeper()#