[x264-devel] [patch] Prefer clock_gettime(CLOCK_MONOTONIC) on Linux.

Petter Reinholdtsen pere at hungry.com
Sat Jun 16 08:01:32 CEST 2018


This avoid discontinuous jumps in the system time that affect
gettimeofday() on Linux.

Based on patch from Kieran Kunhya found in x264-obe.

diff --git a/common/osdep.c b/common/osdep.c
index 3f43d483..d1eeb6e8 100644
--- a/common/osdep.c
+++ b/common/osdep.c
@@ -51,6 +51,10 @@ int64_t x264_mdate( void )
     struct timeb tb;
     ftime( &tb );
     return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000;
+#elif SYS_LINUX
+    struct timespec ts_current;
+    clock_gettime( CLOCK_MONOTONIC, &ts_current );
+    return (int64_t)ts_current.tv_sec * 1000000 + (int64_t)ts_current.tv_nsec / 1000;
 #else
     struct timeval tv_date;
     gettimeofday( &tv_date, NULL );

-- 
Happy hacking
Petter Reinholdtsen


More information about the x264-devel mailing list