From c8dbca8fade0d5c84379cd95f7542d10baa6669d Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Fri, 31 May 2024 17:50:24 -0300 Subject: [PATCH] Use steady/monotonic clock for the timers, so they can handle realtime clock jumps. --- src/gui/Timer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/Timer.h b/src/gui/Timer.h index f4886a0..376efd7 100644 --- a/src/gui/Timer.h +++ b/src/gui/Timer.h @@ -3,16 +3,16 @@ class Timer { public: - Timer() { clock_gettime(CLOCK_REALTIME, &beg_); } + Timer() { clock_gettime(CLOCK_MONOTONIC, &beg_); } double elapsed() { - clock_gettime(CLOCK_REALTIME, &end_); + clock_gettime(CLOCK_MONOTONIC, &end_); return end_.tv_sec - beg_.tv_sec + (end_.tv_nsec - beg_.tv_nsec) / 1000000000.; } - void reset() { clock_gettime(CLOCK_REALTIME, &beg_); } + void reset() { clock_gettime(CLOCK_MONOTONIC, &beg_); } private: timespec beg_, end_; -}; \ No newline at end of file +};