-/* $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>
#include <sys/lock.h>
#include <sys/timeout.h>
#include <sys/mutex.h>
+#include <sys/kernel.h>
#ifdef DDB
#include <machine/db_machdep.h>
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)
{
-/* $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.
#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);