vulp  2.3.0
vulp.utils::SynchronousClock Class Reference

Synchronous (blocking) clock. More...

#include <SynchronousClock.h>

Public Member Functions

 SynchronousClock (double frequency)
 Initialize clock. More...
 
void wait_for_next_tick ()
 Wait until the next tick of the internal clock. More...
 
double measured_period () const noexcept
 Get measured period in seconds. More...
 
int skip_count () const noexcept
 Get last number of clock cycles skipped. More...
 
double slack () const noexcept
 Get the last sleep duration duration in seconds. More...
 

Detailed Description

Synchronous (blocking) clock.

This clock ticks at a fixed frequency. It provides a method to wait for the next tick (which is always blocking, see below), and reports missed ticks if applicable.

The difference between a blocking clock and a rate limiter lies in the behavior when skipping cycles. A rate limiter does nothing if there is no time left, as the caller's rate does not need to be limited. On the contrary, a synchronous clock waits for the next tick, which is by definition in the future, so it always waits for a non-zero duration.

Internally all durations in this class are stored in microseconds.

Definition at line 26 of file SynchronousClock.h.

Constructor & Destructor Documentation

◆ SynchronousClock()

vulp.utils::SynchronousClock::SynchronousClock ( double  frequency)
explicit

Initialize clock.

Parameters
frequencyDesired tick frequency in [Hz]. It should be an integer that divides one million.

Definition at line 20 of file SynchronousClock.cpp.

Member Function Documentation

◆ measured_period()

double vulp.utils::SynchronousClock::measured_period ( ) const
inlinenoexcept

Get measured period in seconds.

Definition at line 45 of file SynchronousClock.h.

◆ skip_count()

int vulp.utils::SynchronousClock::skip_count ( ) const
inlinenoexcept

Get last number of clock cycles skipped.

Definition at line 48 of file SynchronousClock.h.

◆ slack()

double vulp.utils::SynchronousClock::slack ( ) const
inlinenoexcept

Get the last sleep duration duration in seconds.

Definition at line 51 of file SynchronousClock.h.

◆ wait_for_next_tick()

void vulp.utils::SynchronousClock::wait_for_next_tick ( )

Wait until the next tick of the internal clock.

Note
This function will always block and wait for the next tick into the future. It will warn if it detects some missed ticks since the last call.

Definition at line 39 of file SynchronousClock.cpp.


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