mirror of
https://github.com/wiiu-env/NotificationModule.git
synced 2024-11-23 11:59:15 +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,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_;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user