From a869dfea852e0961992b1563b2e14257e7ba3e03 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 14 Aug 2012 19:02:26 +0200 Subject: timer: use monotonic clock if available --- src/timer.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index 691ab76b..2d955070 100644 --- a/src/timer.c +++ b/src/timer.c @@ -20,23 +20,14 @@ #include "config.h" #include "timer.h" #include "audio_format.h" +#include "clock.h" #include #include #include -#include #include -static uint64_t now(void) -{ - struct timeval tv; - - gettimeofday(&tv, NULL); - - return ((uint64_t)tv.tv_sec * 1000000) + tv.tv_usec; -} - struct timer *timer_new(const struct audio_format *af) { struct timer *timer = g_new(struct timer, 1); @@ -54,7 +45,7 @@ void timer_free(struct timer *timer) void timer_start(struct timer *timer) { - timer->time = now(); + timer->time = monotonic_clock_us(); timer->started = 1; } @@ -74,7 +65,7 @@ void timer_add(struct timer *timer, int size) unsigned timer_delay(const struct timer *timer) { - int64_t delay = (int64_t)(timer->time - now()) / 1000; + int64_t delay = (int64_t)(timer->time - monotonic_clock_us()) / 1000; if (delay < 0) return 0; @@ -90,7 +81,7 @@ void timer_sync(struct timer *timer) assert(timer->started); - sleep_duration = timer->time - now(); + sleep_duration = timer->time - monotonic_clock_us(); if (sleep_duration > 0) g_usleep(sleep_duration); } -- cgit v1.2.3