Motion Master
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
MainTimer Class Reference

Cross-platform high-resolution periodic timer. More...

#include <main_timer.h>

Public Member Functions

void wait ()
 Waits for the next timer tick to occur. More...
 
uint64_t getTickCount () const
 Returns the current tick count. More...
 
uint64_t getCycleCount () const
 Returns the number of completed wait cycles. More...
 
uint64_t getCycleMissedTickCount () const
 Returns the number of missed timer ticks in the current cycle. More...
 
int64_t getElapsedTime () const
 Returns the total elapsed time since the timer started. More...
 

Static Public Member Functions

static MainTimergetInstance ()
 Returns the singleton instance of the MainTimer. More...
 
static void notifyAllListeners ()
 Notifies all listeners (waiting threads) about a timer tick. More...
 

Static Public Attributes

static unsigned int DELAY {1}
 Static delay in milliseconds between each timer tick. More...
 
static std::condition_variable cv {}
 Static condition variable used to notify waiting threads of timer ticks. More...
 

Detailed Description

Cross-platform high-resolution periodic timer.

The MainTimer class implements a singleton timer that generates periodic high-resolution timer events. It is designed to be thread-safe and allows other components in the application to synchronize with or wait for timer ticks.

This class supports both Windows and POSIX-compliant systems, providing a consistent interface for time-based operations across platforms.

Member Function Documentation

◆ getCycleCount()

uint64_t MainTimer::getCycleCount ( ) const

Returns the number of completed wait cycles.

A cycle is recorded each time wait() completes successfully.

Returns
Completed cycle count as an unsigned 64-bit integer.

◆ getCycleMissedTickCount()

uint64_t MainTimer::getCycleMissedTickCount ( ) const

Returns the number of missed timer ticks in the current cycle.

Indicates how many ticks were missed due to delays in processing.

Returns
Number of missed ticks as an unsigned 64-bit integer.

◆ getElapsedTime()

int64_t MainTimer::getElapsedTime ( ) const

Returns the total elapsed time since the timer started.

Uses a high-resolution clock to calculate the elapsed time in microseconds.

Returns
Elapsed time in microseconds as a signed 64-bit integer.

◆ getInstance()

MainTimer & MainTimer::getInstance ( )
static

Returns the singleton instance of the MainTimer.

Ensures only one instance of MainTimer exists throughout the application's lifetime. Initializes the timer on the first call.

Returns
Reference to the singleton MainTimer instance.

◆ getTickCount()

uint64_t MainTimer::getTickCount ( ) const

Returns the current tick count.

Tick count increments with each timer tick and reflects the total number of ticks since the timer was started.

Returns
The current tick count as an unsigned 64-bit integer.

◆ notifyAllListeners()

void MainTimer::notifyAllListeners ( )
static

Notifies all listeners (waiting threads) about a timer tick.

Broadcasts a signal using the condition variable to wake any threads waiting for a tick.

◆ wait()

void MainTimer::wait ( )

Waits for the next timer tick to occur.

Blocks the current thread until a tick is received. Tracks missed ticks and updates internal state accordingly.

Member Data Documentation

◆ cv

std::condition_variable MainTimer::cv {}
static

Static condition variable used to notify waiting threads of timer ticks.

◆ DELAY

unsigned int MainTimer::DELAY {1}
static

Static delay in milliseconds between each timer tick.


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