[x264-devel] Prefer a monotonic clock source if available

Henrik Gramner git at videolan.org
Tue Aug 7 00:05:37 CEST 2018


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Mon Jun 25 00:09:51 2018 +0200| [d1a53926fb90e9f4a4f1605f4b2a8a945a73e1d2] | committer: Henrik Gramner

Prefer a monotonic clock source if available

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=d1a53926fb90e9f4a4f1605f4b2a8a945a73e1d2
---

 common/osdep.c | 4 ++++
 configure      | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/common/osdep.c b/common/osdep.c
index 3f43d483..f459c2c2 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 HAVE_CLOCK_GETTIME
+    struct timespec ts;
+    clock_gettime( CLOCK_MONOTONIC, &ts );
+    return (int64_t)ts.tv_sec * 1000000 + (int64_t)ts.tv_nsec / 1000;
 #else
     struct timeval tv_date;
     gettimeofday( &tv_date, NULL );
diff --git a/configure b/configure
index 70fe5764..07ba4490 100755
--- a/configure
+++ b/configure
@@ -396,7 +396,7 @@ NL="
 # list of all preprocessor HAVE values we can define
 CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \
              LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \
-             MSA MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R BITDEPTH8 BITDEPTH10"
+             MSA MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10"
 
 # parse options
 
@@ -1075,6 +1075,13 @@ if cc_check 'string.h' '' 'strtok_r(0, 0, 0);' ; then
     define HAVE_STRTOK_R
 fi
 
+if cc_check 'time.h' '' 'clock_gettime(CLOCK_MONOTONIC, 0);' ; then
+    define HAVE_CLOCK_GETTIME
+elif cc_check 'time.h' '-lrt' 'clock_gettime(CLOCK_MONOTONIC, 0);' ; then
+    define HAVE_CLOCK_GETTIME
+    LDFLAGS="$LDFLAGS -lrt"
+fi
+
 if [ "$SYS" != "WINDOWS" ] && cpp_check "sys/mman.h unistd.h" "" "defined(MAP_PRIVATE)"; then
     define HAVE_MMAP
 fi



More information about the x264-devel mailing list