19#include <condition_variable>
138 std::condition_variable cv_;
141 unsigned int timerID_;
147 std::atomic<uint64_t> tickCount_;
150 std::atomic<uint64_t> cycleCount_;
153 std::atomic<uint64_t> prevTickCount_;
156 std::atomic<uint64_t> cycleMissedTickCount_;
162 std::chrono::steady_clock::time_point lastWaitTime_{};
165 std::atomic<int64_t> waitIntervalUs_{0};
181 MainTimer(
const MainTimer&) =
delete;
184 MainTimer& operator=(
const MainTimer&) =
delete;
198 static void CALLBACK TimerCallback(
unsigned int uID,
unsigned int uMsg,
199 DWORD_PTR dwUser, DWORD_PTR dw1,
213 static void timer_handler(
int sig);
284 std::atomic<uint64_t> tickCount_;
287 std::atomic<uint64_t> refTickCount_;
290 std::atomic<uint64_t> cycleCount_;
Listener for periodic ticks from a MainTimer.
Definition: timer.h:234
void wait()
Waits for the next timer tick and updates internal state.
Definition: timer.cc:158
MainTimerListener()
Constructs a new MainTimerListener instance.
Definition: timer.cc:150
uint64_t getCycleCount() const
Returns the number of completed wait cycles.
Definition: timer.cc:198
uint64_t getTickCount() const
Returns the number of ticks since the first tick received.
Definition: timer.cc:196
int64_t getElapsedTime() const
Returns the total elapsed time since the listener was created.
Definition: timer.cc:200
Cross-platform high-resolution periodic timer.
Definition: timer.h:35
uint64_t getCycleMissedTickCount() const
Returns the number of missed timer ticks in the current cycle.
Definition: timer.cc:137
static void notifyAllListeners()
Notifies all listeners (waiting threads) about a timer tick.
Definition: timer.cc:15
static std::mutex listenerMx
Static mutex protecting the static condition variable for notifying all listener threads.
Definition: timer.h:50
int64_t getElapsedTime() const
Returns the total elapsed time since the timer started.
Definition: timer.cc:141
uint64_t getTickCount() const
Returns the current tick count.
Definition: timer.cc:133
static MainTimer & getInstance()
Returns the singleton instance of the MainTimer.
Definition: timer.cc:10
int64_t getWaitIntervalUs() const
Returns the interval in microseconds between two consecutive wait() calls.
Definition: timer.cc:148
static unsigned int DELAY_MS
Static delay in milliseconds between each timer tick.
Definition: timer.h:40
void wait()
Waits for the next timer tick to occur.
Definition: timer.cc:91
static std::condition_variable listenerCv
Static condition variable used to notify all listener threads of timer ticks.
Definition: timer.h:60
uint64_t getCycleCount() const
Returns the number of completed wait cycles.
Definition: timer.cc:135