From ebecb6f6a11bb418dd054cf12a2673ca0d9eac37 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sun, 15 Apr 2012 15:28:29 +0200 Subject: Implements generalized import hooks. Thanks to Alexander V. Chernikov for the original patch. --- sysdep/unix/timer.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'sysdep') diff --git a/sysdep/unix/timer.h b/sysdep/unix/timer.h index a20df483..a788ae27 100644 --- a/sysdep/unix/timer.h +++ b/sysdep/unix/timer.h @@ -30,6 +30,22 @@ void tm_start(timer *, unsigned after); void tm_stop(timer *); void tm_dump_all(void); +extern bird_clock_t now; /* Relative, monotonic time in seconds */ +extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */ + +static inline bird_clock_t +tm_remains(timer *t) +{ + return t->expires ? t->expires - now : 0; +} + +static inline void +tm_start_max(timer *t, unsigned after) +{ + bird_clock_t rem = tm_remains(t); + tm_start(t, (rem > after) ? rem : after); +} + static inline timer * tm_new_set(pool *p, void (*hook)(struct timer *), void *data, unsigned rand, unsigned rec) { @@ -41,8 +57,6 @@ tm_new_set(pool *p, void (*hook)(struct timer *), void *data, unsigned rand, uns return t; } -extern bird_clock_t now; /* Relative, monotonic time in seconds */ -extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */ struct timeformat { char *fmt1, *fmt2; -- cgit v1.2.3