From: blambert Date: Fri, 11 Jul 2008 14:18:39 +0000 (+0000) Subject: Add timeout_add_{tv,ts,bt,sec,usec,nsec} so that we can add timeouts X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a3687d8a93a47eb289dfdeb15514b7d881aeaf22;p=openbsd 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@ --- 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 * Copyright (c) 2000-2001 Artur Grabowski @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef DDB #include @@ -182,6 +183,71 @@ timeout_add(struct timeout *new, int to_ticks) mtx_leave(&timeout_mutex); } +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) { 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 * 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);