diff options
author | 2008-07-11 14:18:39 +0000 | |
---|---|---|
committer | 2008-07-11 14:18:39 +0000 | |
commit | a3687d8a93a47eb289dfdeb15514b7d881aeaf22 (patch) | |
tree | bf50bd230431b686c4206a1bd6561984498bfa6f /sys/kern/kern_timeout.c | |
parent | de-__inline a trio of functions to shave some space. (diff) | |
download | wireguard-openbsd-a3687d8a93a47eb289dfdeb15514b7d881aeaf22.tar.xz wireguard-openbsd-a3687d8a93a47eb289dfdeb15514b7d881aeaf22.zip |
Add timeout_add_{tv,ts,bt,sec,usec,nsec} so that we can add timeouts
in something other than clock ticks. From art@'s punchlist and (for
the time being) not yet used.
"you're doing it wrong" art@,ray@,otto@,tedu@
ok art@
Diffstat (limited to 'sys/kern/kern_timeout.c')
-rw-r--r-- | sys/kern/kern_timeout.c | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index 1ae52807ba5..5916de193a8 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_timeout.c,v 1.26 2008/01/20 18:23:38 miod Exp $ */ +/* $OpenBSD: kern_timeout.c,v 1.27 2008/07/11 14:18:39 blambert Exp $ */ /* * Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org> * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org> @@ -30,6 +30,7 @@ #include <sys/lock.h> #include <sys/timeout.h> #include <sys/mutex.h> +#include <sys/kernel.h> #ifdef DDB #include <machine/db_machdep.h> @@ -183,6 +184,71 @@ timeout_add(struct timeout *new, int to_ticks) } void +timeout_add_tv(struct timeout *to, struct timeval *tv) +{ + long long to_ticks; + + to_ticks = (long long)hz * tv->tv_sec + tv->tv_usec / tick; + if (to_ticks > INT_MAX) + to_ticks = INT_MAX; + + timeout_add(to, (int)to_ticks); +} + +void +timeout_add_ts(struct timeout *to, struct timespec *ts) +{ + long long to_ticks; + + to_ticks = (long long)hz * ts->tv_sec + ts->tv_nsec / (tick * 1000); + if (to_ticks > INT_MAX) + to_ticks = INT_MAX; + + timeout_add(to, (int)to_ticks); +} + +void +timeout_add_bt(struct timeout *to, struct bintime *bt) +{ + long long to_ticks; + + to_ticks = (long long)hz * bt->sec + (long)(((uint64_t)1000000 * + (uint32_t)(bt->frac >> 32)) >> 32) / tick; + if (to_ticks > INT_MAX) + to_ticks = INT_MAX; + + timeout_add(to, (int)to_ticks); +} + +void +timeout_add_sec(struct timeout *to, int secs) +{ + long long to_ticks; + + to_ticks = (long long)hz * secs; + if (to_ticks > INT_MAX) + to_ticks = INT_MAX; + + timeout_add(to, (int)to_ticks); +} + +void +timeout_add_usec(struct timeout *to, int usecs) +{ + int to_ticks = usecs / tick; + + timeout_add(to, to_ticks); +} + +void +timeout_add_nsec(struct timeout *to, int nsecs) +{ + int to_ticks = nsecs / (tick * 1000); + + timeout_add(to, to_ticks); +} + +void timeout_del(struct timeout *to) { mtx_enter(&timeout_mutex); |