summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2013-11-27 04:28:33 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2013-11-27 04:28:33 +0000
commitb948ce6d7fb9d00fc6d81440c298350a2bcf197a (patch)
treede3f35226c2c1b43e105958d6365605254144329 /sys
parent4650bdbc69748bba813ff0be32c2bf32b4d6c1d7 (diff)
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@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_timeout.c36
-rw-r--r--sys/sys/timeout.h18
2 files changed, 29 insertions, 25 deletions
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);