summaryrefslogtreecommitdiff
path: root/sysdep/unix
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2012-04-15 15:28:29 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2012-04-15 15:28:29 +0200
commitebecb6f6a11bb418dd054cf12a2673ca0d9eac37 (patch)
tree9454aad3bd2e84fc65b518574aa9d112a0e5155c /sysdep/unix
parentae8b300164a975597f9b6caea0b205af2e4db30b (diff)
Implements generalized import hooks.
Thanks to Alexander V. Chernikov for the original patch.
Diffstat (limited to 'sysdep/unix')
-rw-r--r--sysdep/unix/timer.h18
1 files changed, 16 insertions, 2 deletions
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;