aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/time.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2014-08-24 18:14:47 +0200
committerLuca Barbato <lu_zero@gentoo.org>2014-09-03 02:38:03 +0200
commitebef9f5a56d7df91e010a177a80cfc8dbe394305 (patch)
treec508c8775aa760085a599d3d65e7ca24bc0225e8 /libavutil/time.c
parent65e78a2e4b111627c0ebdf2c9baec95e5e21560d (diff)
downloadffmpeg-ebef9f5a56d7df91e010a177a80cfc8dbe394305.tar.gz
time: Use clock_gettime if the monotonic clock is available
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavutil/time.c')
-rw-r--r--libavutil/time.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/libavutil/time.c b/libavutil/time.c
index 62cd445dbc..e833cd0d17 100644
--- a/libavutil/time.c
+++ b/libavutil/time.c
@@ -21,7 +21,9 @@
#include <stddef.h>
#include <stdint.h>
#include <time.h>
-#if HAVE_GETTIMEOFDAY
+#if HAVE_CLOCK_GETTIME
+#include <time.h>
+#elif HAVE_GETTIMEOFDAY
#include <sys/time.h>
#endif
#if HAVE_UNISTD_H
@@ -36,7 +38,11 @@
int64_t av_gettime(void)
{
-#if HAVE_GETTIMEOFDAY
+#if HAVE_CLOCK_GETTIME
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (int64_t)ts.tv_sec * 100000 + ts.tv_nsec / 1000;
+#elif HAVE_GETTIMEOFDAY
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;