1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

on Linux, use CLOCK_MONOTONIC for clock_gettime()

On Linux systems which are being driven by an external time source (NTP or PTP), it is possible that time appears to slew in reverse under `CLOCK_REALTIME`. Since the timer function is used to time durations of events (calls to `select()`), it is better to use `CLOCK_MONOTONIC`, which isn't subject to slewing.
This commit is contained in:
Patrick O'Leary 2015-11-10 09:40:30 -06:00
parent ef7f77d411
commit 98f1c31e81

View File

@ -91,7 +91,7 @@ MillisecondTimer::timespec_now ()
time.tv_sec = mts.tv_sec;
time.tv_nsec = mts.tv_nsec;
# else
clock_gettime(CLOCK_REALTIME, &time);
clock_gettime(CLOCK_MONOTONIC, &time);
# endif
return time;
}