diff options
author | Max Kellermann <max@duempel.org> | 2010-11-05 09:39:50 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-11-05 09:39:56 +0100 |
commit | ad430c661780ed196d772564f9a49d5dacb5df0f (patch) | |
tree | 3038fd6ebea6663a3942428552b66e480ea74982 | |
parent | ec48b5ea3ac25d4b27c3b942017309b408fc3ac0 (diff) | |
download | mpd-ad430c661780ed196d772564f9a49d5dacb5df0f.tar.gz mpd-ad430c661780ed196d772564f9a49d5dacb5df0f.tar.xz mpd-ad430c661780ed196d772564f9a49d5dacb5df0f.zip |
timer: add function timer_delay()
-rw-r--r-- | src/timer.c | 13 | ||||
-rw-r--r-- | src/timer.h | 6 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/timer.c b/src/timer.c index 57ad8d0ed..49c2ee3ac 100644 --- a/src/timer.c +++ b/src/timer.c @@ -71,6 +71,19 @@ void timer_add(Timer *timer, int size) timer->time += ((uint64_t)size * 1000000) / timer->rate; } +unsigned +timer_delay(const Timer *timer) +{ + int64_t delay = timer->time - now(); + if (delay < 0) + return 0; + + if (delay > 1000 * 1000 * 1000) + return 1000 * 1000; + + return delay / 1000; +} + void timer_sync(Timer *timer) { int64_t sleep_duration; diff --git a/src/timer.h b/src/timer.h index 684367bc5..bbd895b31 100644 --- a/src/timer.h +++ b/src/timer.h @@ -40,6 +40,12 @@ void timer_reset(Timer *timer); void timer_add(Timer *timer, int size); +/** + * Returns the number of milliseconds to sleep to get back to sync. + */ +unsigned +timer_delay(const Timer *timer); + void timer_sync(Timer *timer); #endif |