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
This commit is contained in:
Gleb Smirnoff 2005-09-08 14:20:39 +00:00
parent e1ab829ad2
commit d04304d155
3 changed files with 16 additions and 9 deletions

View File

@ -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 ,

View File

@ -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

View File

@ -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);