aboutsummaryrefslogtreecommitdiffstats
path: root/src/timer.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-14 23:58:54 +0200
committerMax Kellermann <max@duempel.org>2012-08-14 23:58:54 +0200
commit7d27d2ea5e8b622a288c80518bc0daec53dbbc93 (patch)
treeb1b9e98369919d66869b3ff1626372bf16a38c23 /src/timer.c
parent5cc3338267214eb050e39bc509d8b4258cec6afd (diff)
parentdc22846d58264bfae3b4516e2de1614b3b97a5ca (diff)
downloadmpd-7d27d2ea5e8b622a288c80518bc0daec53dbbc93.tar.gz
mpd-7d27d2ea5e8b622a288c80518bc0daec53dbbc93.tar.xz
mpd-7d27d2ea5e8b622a288c80518bc0daec53dbbc93.zip
Merge branch 'v0.17.x'
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/timer.c b/src/timer.c
index 691ab76be..2d9550706 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 <glib.h>
#include <assert.h>
#include <limits.h>
-#include <sys/time.h>
#include <stddef.h>
-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);
}