summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2013-11-27 04:28:32 +0000
committerdlg <dlg@openbsd.org>2013-11-27 04:28:32 +0000
commit1697ea25319307d409778fe0474580a85b933c55 (patch)
treeb6ad240fd4beb7810aa4f782bd5fd62596daac0b
parentuse a macro when testing for an ich8 family mac type (diff)
downloadwireguard-openbsd-1697ea25319307d409778fe0474580a85b933c55.tar.xz
wireguard-openbsd-1697ea25319307d409778fe0474580a85b933c55.zip
make timeout_add and its wrappers return whether the timeout was scheduled
in this call by returning 1, or a previous call by returning 0. this makes it easy to refcount the stuff we're scheduling a timeout for, and brings the api in line with what task_add(9) provides. ok mpi@ matthew@ mikeb@ guenther@
-rw-r--r--share/man/man9/timeout.925
-rw-r--r--sys/kern/kern_timeout.c36
-rw-r--r--sys/sys/timeout.h18
3 files changed, 43 insertions, 36 deletions
diff --git a/share/man/man9/timeout.9 b/share/man/man9/timeout.9
index a14c0a158be..fe80ea90683 100644
--- a/share/man/man9/timeout.9
+++ b/share/man/man9/timeout.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: timeout.9,v 1.32 2013/06/04 19:27:14 schwarze Exp $
+.\" $OpenBSD: timeout.9,v 1.33 2013/11/27 04:28:32 dlg Exp $
.\"
.\" Copyright (c) 2000 Artur Grabowski <art@openbsd.org>
.\" All rights reserved.
@@ -23,7 +23,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 4 2013 $
+.Dd $Mdocdate: November 27 2013 $
.Dt TIMEOUT 9
.Os
.Sh NAME
@@ -46,7 +46,7 @@
.In sys/timeout.h
.Ft void
.Fn "timeout_set" "struct timeout *to" "void (*fn)(void *)" "void *arg"
-.Ft void
+.Ft int
.Fn "timeout_add" "struct timeout *to" "int ticks"
.Ft int
.Fn "timeout_del" "struct timeout *to"
@@ -56,19 +56,19 @@
.Fn "timeout_initialized" "struct timeout *to"
.Ft int
.Fn "timeout_triggered" "struct timeout *to"
-.Ft void
+.Ft int
.Fn "timeout_add_tv" "struct timeout *to" "struct timeval *"
-.Ft void
+.Ft int
.Fn "timeout_add_ts" "struct timeout *to" "struct timespec *"
-.Ft void
+.Ft int
.Fn "timeout_add_bt" "struct timeout *to" "struct bintime *"
-.Ft void
+.Ft int
.Fn "timeout_add_sec" "struct timeout *to" "int sec"
-.Ft void
+.Ft int
.Fn "timeout_add_msec" "struct timeout *to" "int msec"
-.Ft void
+.Ft int
.Fn "timeout_add_usec" "struct timeout *to" "int usec"
-.Ft void
+.Ft int
.Fn "timeout_add_nsec" "struct timeout *to" "int nsec"
.Sh DESCRIPTION
The
@@ -133,6 +133,9 @@ and may not be used in calls to
.Fn timeout_set
until it has timed out or been removed with
.Fn timeout_del .
+If the timeout was not already scheduled by a previous call to
+.Fn timeout_add
+it will return 1, otherwise 0.
If the timeout in the
.Fa to
argument is already scheduled, the old execution time will be
@@ -146,7 +149,7 @@ If the timeout has already executed or has never been added
the call will have no effect.
If the timeout was actually removed by
.Fn timeout_del
-it will return 1.
+it will return 1, otherwise 0.
.Pp
The
.Fn timeout_pending
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index 2831fc3455e..18968781fa2 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_timeout.c,v 1.40 2013/10/06 04:34:35 guenther Exp $ */
+/* $OpenBSD: kern_timeout.c,v 1.41 2013/11/27 04:28:32 dlg Exp $ */
/*
* Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org>
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
@@ -162,10 +162,11 @@ timeout_set(struct timeout *new, void (*fn)(void *), void *arg)
}
-void
+int
timeout_add(struct timeout *new, int to_ticks)
{
int old_time;
+ int ret = 1;
#ifdef DIAGNOSTIC
if (!(new->to_flags & TIMEOUT_INITIALIZED))
@@ -190,14 +191,17 @@ timeout_add(struct timeout *new, int to_ticks)
CIRCQ_REMOVE(&new->to_list);
CIRCQ_INSERT(&new->to_list, &timeout_todo);
}
+ ret = 0;
} else {
new->to_flags |= TIMEOUT_ONQUEUE;
CIRCQ_INSERT(&new->to_list, &timeout_todo);
}
mtx_leave(&timeout_mutex);
+
+ return (ret);
}
-void
+int
timeout_add_tv(struct timeout *to, const struct timeval *tv)
{
long long to_ticks;
@@ -206,10 +210,10 @@ timeout_add_tv(struct timeout *to, const struct timeval *tv)
if (to_ticks > INT_MAX)
to_ticks = INT_MAX;
- timeout_add(to, (int)to_ticks);
+ return (timeout_add(to, (int)to_ticks));
}
-void
+int
timeout_add_ts(struct timeout *to, const struct timespec *ts)
{
long long to_ticks;
@@ -218,10 +222,10 @@ timeout_add_ts(struct timeout *to, const struct timespec *ts)
if (to_ticks > INT_MAX)
to_ticks = INT_MAX;
- timeout_add(to, (int)to_ticks);
+ return (timeout_add(to, (int)to_ticks));
}
-void
+int
timeout_add_bt(struct timeout *to, const struct bintime *bt)
{
long long to_ticks;
@@ -231,10 +235,10 @@ timeout_add_bt(struct timeout *to, const struct bintime *bt)
if (to_ticks > INT_MAX)
to_ticks = INT_MAX;
- timeout_add(to, (int)to_ticks);
+ return (timeout_add(to, (int)to_ticks));
}
-void
+int
timeout_add_sec(struct timeout *to, int secs)
{
long long to_ticks;
@@ -243,10 +247,10 @@ timeout_add_sec(struct timeout *to, int secs)
if (to_ticks > INT_MAX)
to_ticks = INT_MAX;
- timeout_add(to, (int)to_ticks);
+ return (timeout_add(to, (int)to_ticks));
}
-void
+int
timeout_add_msec(struct timeout *to, int msecs)
{
long long to_ticks;
@@ -255,23 +259,23 @@ timeout_add_msec(struct timeout *to, int msecs)
if (to_ticks > INT_MAX)
to_ticks = INT_MAX;
- timeout_add(to, (int)to_ticks);
+ return (timeout_add(to, (int)to_ticks));
}
-void
+int
timeout_add_usec(struct timeout *to, int usecs)
{
int to_ticks = usecs / tick;
- timeout_add(to, to_ticks);
+ return (timeout_add(to, to_ticks));
}
-void
+int
timeout_add_nsec(struct timeout *to, int nsecs)
{
int to_ticks = nsecs / (tick * 1000);
- timeout_add(to, to_ticks);
+ return (timeout_add(to, to_ticks));
}
int
diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h
index 8b3ae0915e8..ddb7624c1c6 100644
--- a/sys/sys/timeout.h
+++ b/sys/sys/timeout.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: timeout.h,v 1.23 2013/10/23 20:12:05 deraadt Exp $ */
+/* $OpenBSD: timeout.h,v 1.24 2013/11/27 04:28:32 dlg Exp $ */
/*
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -85,14 +85,14 @@ struct timeout {
struct bintime;
void timeout_set(struct timeout *, void (*)(void *), void *);
-void timeout_add(struct timeout *, int);
-void timeout_add_tv(struct timeout *, const struct timeval *);
-void timeout_add_ts(struct timeout *, const struct timespec *);
-void timeout_add_bt(struct timeout *, const struct bintime *);
-void timeout_add_sec(struct timeout *, int);
-void timeout_add_msec(struct timeout *, int);
-void timeout_add_usec(struct timeout *, int);
-void timeout_add_nsec(struct timeout *, int);
+int timeout_add(struct timeout *, int);
+int timeout_add_tv(struct timeout *, const struct timeval *);
+int timeout_add_ts(struct timeout *, const struct timespec *);
+int timeout_add_bt(struct timeout *, const struct bintime *);
+int timeout_add_sec(struct timeout *, int);
+int timeout_add_msec(struct timeout *, int);
+int timeout_add_usec(struct timeout *, int);
+int timeout_add_nsec(struct timeout *, int);
int timeout_del(struct timeout *);
void timeout_startup(void);