Motion Master
|
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 MainTimer & | getInstance () |
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... | |
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.
uint64_t MainTimer::getCycleCount | ( | ) | const |
Returns the number of completed wait cycles.
A cycle is recorded each time wait()
completes successfully.
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.
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.
|
static |
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.
|
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.
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.
|
static |
Static condition variable used to notify waiting threads of timer ticks.
|
static |
Static delay in milliseconds between each timer tick.