Motion Master
|
Cross-platform high-resolution periodic timer. More...
#include <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... | |
int64_t | getWaitIntervalUs () const |
Returns the interval in microseconds between two consecutive wait() calls. 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_MS {1} |
Static delay in milliseconds between each timer tick. More... | |
static std::mutex | listenerMx {} |
Static mutex protecting the static condition variable for notifying all listener threads. More... | |
static std::condition_variable | listenerCv {} |
Static condition variable used to notify all listener 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 mm::core::timer::MainTimer::getCycleCount | ( | ) | const |
Returns the number of completed wait cycles.
A cycle is recorded each time wait()
completes successfully.
uint64_t mm::core::timer::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 mm::core::timer::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 mm::core::timer::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.
int64_t mm::core::timer::MainTimer::getWaitIntervalUs | ( | ) | const |
Returns the interval in microseconds between two consecutive wait()
calls.
|
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 mm::core::timer::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 delay in milliseconds between each timer tick.
|
static |
Static condition variable used to notify all listener threads of timer ticks.
This condition variable works together with the static mutex listenerMx
to safely synchronize notification and waiting of multiple listener threads.
|
static |
Static mutex protecting the static condition variable for notifying all listener threads.
This mutex must be locked whenever waiting on or notifying the static condition variable to ensure thread-safe synchronization across all listeners.