commit c81e65ca38d0ea6fdf61d1fb08933d29282c0b71 Author: Ryota Ozaki Date: Wed Feb 28 14:08:16 2018 +0900 Let callout_reset and callout_schedule return if it reschedules a pending callout or not diff --git a/share/man/man9/callout.9 b/share/man/man9/callout.9 index 29a099f59fc..0cc17a008f4 100644 --- a/share/man/man9/callout.9 +++ b/share/man/man9/callout.9 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 21, 2014 +.Dd February 28, 2018 .Dt CALLOUT 9 .Os .Sh NAME @@ -49,10 +49,10 @@ .Fn "callout_init" "callout_t *c" "u_int flags" .Ft void .Fn "callout_destroy" "callout_t *c" -.Ft void +.Ft bool .Fn "callout_reset" "callout_t *c" "int ticks" \ "void (*func)(void *)" "void *arg" -.Ft void +.Ft bool .Fn "callout_schedule" "callout_t *c" "int ticks" .Ft void .Fn "callout_setfunc" "callout_t *c" "void (*func)(void *)" "void *arg" @@ -145,6 +145,9 @@ and and the .Em PENDING status is cleared. +.Fn callout_reset +returns true if it reschedules a pending callout with a newly specified +time and returns false otherwise. .Pp The .Fn callout_setfunc diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index 02696442f37..add2c64171e 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -326,7 +326,7 @@ callout_destroy(callout_t *cs) * already be set in the callout structure. Must be called with * callout_lock. */ -static void +static bool callout_schedule_locked(callout_impl_t *c, kmutex_t *lock, int to_ticks) { struct callout_cpu *cc, *occ; @@ -353,7 +353,7 @@ callout_schedule_locked(callout_impl_t *c, kmutex_t *lock, int to_ticks) CIRCQ_INSERT(&c->c_list, &occ->cc_todo); } mutex_spin_exit(lock); - return; + return true; } cc = curcpu()->ci_data.cpu_callout; @@ -372,6 +372,7 @@ callout_schedule_locked(callout_impl_t *c, kmutex_t *lock, int to_ticks) mutex_spin_exit(cc->cc_lock); } mutex_spin_exit(lock); + return false; } /* @@ -380,7 +381,7 @@ callout_schedule_locked(callout_impl_t *c, kmutex_t *lock, int to_ticks) * Reset a callout structure with a new function and argument, and * schedule it to run. */ -void +bool callout_reset(callout_t *cs, int to_ticks, void (*func)(void *), void *arg) { callout_impl_t *c = (callout_impl_t *)cs; @@ -392,7 +393,7 @@ callout_reset(callout_t *cs, int to_ticks, void (*func)(void *), void *arg) lock = callout_lock(c); c->c_func = func; c->c_arg = arg; - callout_schedule_locked(c, lock, to_ticks); + return callout_schedule_locked(c, lock, to_ticks); } /* @@ -401,7 +402,7 @@ callout_reset(callout_t *cs, int to_ticks, void (*func)(void *), void *arg) * Schedule a callout to run. The function and argument must * already be set in the callout structure. */ -void +bool callout_schedule(callout_t *cs, int to_ticks) { callout_impl_t *c = (callout_impl_t *)cs; @@ -410,7 +411,7 @@ callout_schedule(callout_t *cs, int to_ticks) KASSERT(c->c_magic == CALLOUT_MAGIC); lock = callout_lock(c); - callout_schedule_locked(c, lock, to_ticks); + return callout_schedule_locked(c, lock, to_ticks); } /* diff --git a/sys/sys/callout.h b/sys/sys/callout.h index 0214b21fb05..4c4ff2e4cf2 100644 --- a/sys/sys/callout.h +++ b/sys/sys/callout.h @@ -111,8 +111,8 @@ void callout_hardclock(void); void callout_init(callout_t *, u_int); void callout_destroy(callout_t *); void callout_setfunc(callout_t *, void (*)(void *), void *); -void callout_reset(callout_t *, int, void (*)(void *), void *); -void callout_schedule(callout_t *, int); +bool callout_reset(callout_t *, int, void (*)(void *), void *); +bool callout_schedule(callout_t *, int); bool callout_stop(callout_t *); bool callout_halt(callout_t *, void *); bool callout_pending(callout_t *);