mirror of
https://github.com/wiiu-env/NotificationModule.git
synced 2024-11-17 17:29:16 +01:00
Use steady/monotonic clock for the timers, so they can handle realtime clock jumps.
This commit is contained in:
parent
36993e1630
commit
c8dbca8fad
@ -3,15 +3,15 @@
|
|||||||
|
|
||||||
class Timer {
|
class Timer {
|
||||||
public:
|
public:
|
||||||
Timer() { clock_gettime(CLOCK_REALTIME, &beg_); }
|
Timer() { clock_gettime(CLOCK_MONOTONIC, &beg_); }
|
||||||
|
|
||||||
double elapsed() {
|
double elapsed() {
|
||||||
clock_gettime(CLOCK_REALTIME, &end_);
|
clock_gettime(CLOCK_MONOTONIC, &end_);
|
||||||
return end_.tv_sec - beg_.tv_sec +
|
return end_.tv_sec - beg_.tv_sec +
|
||||||
(end_.tv_nsec - beg_.tv_nsec) / 1000000000.;
|
(end_.tv_nsec - beg_.tv_nsec) / 1000000000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() { clock_gettime(CLOCK_REALTIME, &beg_); }
|
void reset() { clock_gettime(CLOCK_MONOTONIC, &beg_); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
timespec beg_, end_;
|
timespec beg_, end_;
|
||||||
|
Loading…
Reference in New Issue
Block a user