Skip to content

Commit

Permalink
Use steady/monotonic clock for the timers, so they can handle realtim…
Browse files Browse the repository at this point in the history
…e clock jumps.
  • Loading branch information
Daniel K. O. (dkosmari) authored and Maschell committed Jun 1, 2024
1 parent 36993e1 commit c8dbca8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/gui/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
};

0 comments on commit c8dbca8

Please sign in to comment.