summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorblambert <blambert@openbsd.org>2008-07-11 14:18:39 +0000
committerblambert <blambert@openbsd.org>2008-07-11 14:18:39 +0000
commita3687d8a93a47eb289dfdeb15514b7d881aeaf22 (patch)
treebf50bd230431b686c4206a1bd6561984498bfa6f /sys
parentde-__inline a trio of functions to shave some space. (diff)
downloadwireguard-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')
-rw-r--r--sys/kern/kern_timeout.c68
-rw-r--r--sys/sys/timeout.h8
2 files changed, 74 insertions, 2 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);
diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h
index 3f8676bb14a..283cf365119 100644
--- a/sys/sys/timeout.h
+++ b/sys/sys/timeout.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: timeout.h,v 1.16 2003/06/03 01:27:31 art Exp $ */
+/* $OpenBSD: timeout.h,v 1.17 2008/07/11 14:18:39 blambert Exp $ */
/*
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -83,6 +83,12 @@ struct timeout {
#ifdef _KERNEL
void timeout_set(struct timeout *, void (*)(void *), void *);
void timeout_add(struct timeout *, int);
+void timeout_add_tv(struct timeout *, struct timeval *);
+void timeout_add_ts(struct timeout *, struct timespec *);
+void timeout_add_bt(struct timeout *, struct bintime *);
+void timeout_add_sec(struct timeout *, int);
+void timeout_add_usec(struct timeout *, int);
+void timeout_add_nsec(struct timeout *, int);
void timeout_del(struct timeout *);
void timeout_startup(void);