aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2005-09-08 14:20:39 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2005-09-08 14:20:39 +0000
commitd04304d15550b2149a0bb9fccaa4ac50f29229c6 (patch)
tree28d972cf1fcd2514ba5a8b5fca4778e5e77c5548
parente1ab829ad27af06df1ee508492022d5ca8f3e34d (diff)
downloadsrc-d04304d15550b2149a0bb9fccaa4ac50f29229c6.tar.gz
src-d04304d15550b2149a0bb9fccaa4ac50f29229c6.zip
Make callout_reset() return a non-zero value if a pending callout
was rescheduled. If there was no pending callout, then return 0. Reviewed by: iedowse, cperciva
Notes
Notes: svn path=/head/; revision=149879
-rw-r--r--share/man/man9/timeout.912
-rw-r--r--sys/kern/kern_timeout.c11
-rw-r--r--sys/sys/callout.h2
3 files changed, 16 insertions, 9 deletions
diff --git a/share/man/man9/timeout.9 b/share/man/man9/timeout.9
index 1589aed12e13..d683e32f69af 100644
--- a/share/man/man9/timeout.9
+++ b/share/man/man9/timeout.9
@@ -36,7 +36,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 6, 2005
+.Dd September 8, 2005
.Dt TIMEOUT 9
.Os
.Sh NAME
@@ -77,7 +77,7 @@ struct callout_handle handle = CALLOUT_HANDLE_INITIALIZER(&handle)
.Fn callout_stop "struct callout *c"
.Ft int
.Fn callout_drain "struct callout *c"
-.Ft void
+.Ft int
.Fn callout_reset "struct callout *c" "int ticks" "timeout_t *func" "void *arg"
.Ft int
.Fn callout_pending "struct callout *c"
@@ -260,6 +260,9 @@ first performs the equivalent of
to disestablish the callout, and then establishes a new callout in the
same manner as
.Fn timeout .
+If there was already a pending callout and it was rescheduled, then
+.Fn callout_reset
+will return a non-zero value.
If the callout has an associated mutex, then that mutex must be
held when this function is called.
.Pp
@@ -346,6 +349,8 @@ before destroying the callout or its associated mutex.
.It
The return value from
.Fn callout_stop
+and
+.Fn callout_reset
indicates whether or not the callout was removed.
If it is known that the callout was set and the callout function has
not yet executed, then a return value of
@@ -366,9 +371,6 @@ if (sc->sc_flags & SCFLG_CALLOUT_RUNNING) {
}
.Ed
.Pp
-Note that there is no equivalent mechanism to determine whether or not
-.Fn callout_reset
-stopped the callout.
.It
The
.Fn callout_pending ,
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index f2fafbb85dfa..8e6b183bb76f 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -427,13 +427,14 @@ callout_handle_init(struct callout_handle *handle)
* callout_pending() - returns truth if callout is still waiting for timeout
* callout_deactivate() - marks the callout as having been serviced
*/
-void
+int
callout_reset(c, to_ticks, ftn, arg)
struct callout *c;
int to_ticks;
void (*ftn)(void *);
void *arg;
{
+ int cancelled = 0;
#ifdef notyet /* Some callers of timeout() do not hold Giant. */
if (c->c_mtx != NULL)
@@ -448,14 +449,14 @@ callout_reset(c, to_ticks, ftn, arg)
* can cancel the callout if it has not really started.
*/
if (c->c_mtx != NULL && !curr_cancelled)
- curr_cancelled = 1;
+ cancelled = curr_cancelled = 1;
if (wakeup_needed) {
/*
* Someone has called callout_drain to kill this
* callout. Don't reschedule.
*/
mtx_unlock_spin(&callout_lock);
- return;
+ return (cancelled);
}
}
if (c->c_flags & CALLOUT_PENDING) {
@@ -465,6 +466,8 @@ callout_reset(c, to_ticks, ftn, arg)
TAILQ_REMOVE(&callwheel[c->c_time & callwheelmask], c,
c_links.tqe);
+ cancelled = 1;
+
/*
* Part of the normal "stop a pending callout" process
* is to clear the CALLOUT_ACTIVE and CALLOUT_PENDING
@@ -490,6 +493,8 @@ callout_reset(c, to_ticks, ftn, arg)
TAILQ_INSERT_TAIL(&callwheel[c->c_time & callwheelmask],
c, c_links.tqe);
mtx_unlock_spin(&callout_lock);
+
+ return (cancelled);
}
int
diff --git a/sys/sys/callout.h b/sys/sys/callout.h
index cec907950d0b..a55456254640 100644
--- a/sys/sys/callout.h
+++ b/sys/sys/callout.h
@@ -81,7 +81,7 @@ extern struct mtx callout_lock;
void callout_init(struct callout *, int);
void callout_init_mtx(struct callout *, struct mtx *, int);
#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING)
-void callout_reset(struct callout *, int, void (*)(void *), void *);
+int callout_reset(struct callout *, int, void (*)(void *), void *);
#define callout_stop(c) _callout_stop_safe(c, 0)
int _callout_stop_safe(struct callout *, int);