Skip to content

Commit 2e5fcb2

Browse files
committed
get_time_in_ns: switch to CLOCK_MONOTONIC
(previously TIME_UTC corresponed with CLOCK_REALTIME) The function is intended to measure intervals rather to wall-clock time, so that CLOCK_MONOTONIC is more eligible - if there is a clock jump caused by clock_settime, it may cause problems. Even until now, this was not much likely, anyways, because this would happen just when an administrator sets the time with clock_settime. NTP adjusts the time gradually and never jumps back (see ntp_adjtime()) and it also adjusts both clocks at the same time, anyways (the clock is actually one, REALTIME is adding an fixed offset). Not sure about Windows (where the clock_getime API is provided by MinGW, not the system iteslf).
1 parent 8e47060 commit 2e5fcb2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/tv.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ uint32_t get_std_video_local_mediatime(void)
250250
}
251251

252252
/**
253-
* @returns nanoseconds since implementation defined epoche (timespec_get def)
253+
* @returns nanoseconds since some time point (CLOCK_MONOTONIC)
254254
*/
255255
time_ns_t
256256
get_time_in_ns()
257257
{
258258
struct timespec ts = { 0, 0 };
259-
if (timespec_get(&ts, TIME_UTC) == 0) {
260-
perror("timespec_get");
259+
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
260+
perror("get_time_in_ns: clock_gettime");
261261
}
262262
return (ts.tv_sec * NS_IN_SEC) + ts.tv_nsec;
263263
}

0 commit comments

Comments
 (0)