aboutsummaryrefslogtreecommitdiffstats
path: root/src/timer.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/timer.c13
1 files changed, 13 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;