]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/timeout.9
IFC @r272887
[FreeBSD/FreeBSD.git] / share / man / man9 / timeout.9
1 .\"     $NetBSD: timeout.9,v 1.2 1996/06/23 22:32:34 pk Exp $
2 .\"
3 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Paul Kranenburg.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
22 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
29 .\"
30 .\" $FreeBSD$
31 .\"
32 .Dd October 8, 2014
33 .Dt TIMEOUT 9
34 .Os
35 .Sh NAME
36 .Nm callout_active ,
37 .Nm callout_deactivate ,
38 .Nm callout_drain ,
39 .Nm callout_handle_init ,
40 .Nm callout_init ,
41 .Nm callout_init_mtx ,
42 .Nm callout_init_rm ,
43 .Nm callout_init_rw ,
44 .Nm callout_pending ,
45 .Nm callout_reset ,
46 .Nm callout_reset_curcpu ,
47 .Nm callout_reset_on ,
48 .Nm callout_reset_sbt ,
49 .Nm callout_reset_sbt_curcpu ,
50 .Nm callout_reset_sbt_on ,
51 .Nm callout_schedule ,
52 .Nm callout_schedule_curcpu ,
53 .Nm callout_schedule_on ,
54 .Nm callout_stop ,
55 .Nm timeout ,
56 .Nm untimeout
57 .Nd execute a function after a specified length of time
58 .Sh SYNOPSIS
59 .In sys/types.h
60 .In sys/systm.h
61 .Bd -literal
62 typedef void timeout_t (void *);
63 .Ed
64 .Ft int
65 .Fn callout_active "struct callout *c"
66 .Ft void
67 .Fn callout_deactivate "struct callout *c"
68 .Ft int
69 .Fn callout_drain "struct callout *c"
70 .Ft void
71 .Fn callout_handle_init "struct callout_handle *handle"
72 .Bd -literal
73 struct callout_handle handle = CALLOUT_HANDLE_INITIALIZER(&handle);
74 .Ed
75 .Ft void
76 .Fn callout_init "struct callout *c" "int mpsafe"
77 .Ft void
78 .Fn callout_init_mtx "struct callout *c" "struct mtx *mtx" "int flags"
79 .Ft void
80 .Fn callout_init_rm "struct callout *c" "struct rmlock *rm" "int flags"
81 .Ft void
82 .Fn callout_init_rw "struct callout *c" "struct rwlock *rw" "int flags"
83 .Ft int
84 .Fn callout_pending "struct callout *c"
85 .Ft int
86 .Fn callout_reset "struct callout *c" "int ticks" "timeout_t *func" "void *arg"
87 .Ft int
88 .Fn callout_reset_curcpu "struct callout *c" "int ticks" "timeout_t *func" \
89 "void *arg"
90 .Ft int
91 .Fn callout_reset_on "struct callout *c" "int ticks" "timeout_t *func" \
92 "void *arg" "int cpu"
93 .Ft int
94 .Fn callout_reset_sbt "struct callout *c" "sbintime_t sbt" \
95 "sbintime_t pr" "timeout_t *func" "void *arg" "int flags"
96 .Ft int
97 .Fn callout_reset_sbt_curcpu "struct callout *c" "sbintime_t sbt" \
98 "sbintime_t pr" "timeout_t *func" "void *arg" "int flags"
99 .Ft int
100 .Fn callout_reset_sbt_on "struct callout *c" "sbintime_t sbt" \
101 "sbintime_t pr" "timeout_t *func" "void *arg" "int cpu" "int flags"
102 .Ft int
103 .Fn callout_schedule "struct callout *c" "int ticks"
104 .Ft int
105 .Fn callout_schedule_curcpu "struct callout *c" "int ticks"
106 .Ft int
107 .Fn callout_schedule_on "struct callout *c" "int ticks" "int cpu"
108 .Ft int
109 .Fn callout_stop "struct callout *c"
110 .Ft struct callout_handle
111 .Fn timeout "timeout_t *func" "void *arg" "int ticks"
112 .Ft void
113 .Fn untimeout "timeout_t *func" "void *arg" "struct callout_handle handle"
114 .Sh DESCRIPTION
115 The
116 .Nm callout
117 API is used to schedule a call to an arbitrary function at a specific
118 time in the future.
119 Consumers of this API are required to allocate a callout structure
120 .Pq struct callout
121 for each pending function invocation.
122 This structure stores state about the pending function invocation including
123 the function to be called and the time at which the function should be invoked.
124 Pending function calls can be cancelled or rescheduled to a different time.
125 In addition,
126 a callout structure may be reused to schedule a new function call after a
127 scheduled call is completed.
128 .Pp
129 Callouts only provide a single-shot mode.
130 If a consumer requires a periodic timer,
131 it must explicitly reschedule each function call.
132 This is normally done by rescheduling the subsequent call within the called
133 function.
134 .Pp
135 Callout functions must not sleep.
136 They may not acquire sleepable locks,
137 wait on condition variables,
138 perform blocking allocation requests,
139 or invoke any other action that might sleep.
140 .Pp
141 Each callout structure must be initialized by
142 .Fn callout_init ,
143 .Fn callout_init_mtx ,
144 .Fn callout_init_rm ,
145 or
146 .Fn callout_init_rw
147 before it is passed to any of the other callout functions.
148 The
149 .Fn callout_init
150 function initializes a callout structure in
151 .Fa c
152 that is not associated with a specific lock.
153 If the
154 .Fa mpsafe
155 argument is zero,
156 the callout structure is not considered to be
157 .Dq multi-processor safe ;
158 and the Giant lock will be acquired before calling the callout function
159 and released when the callout function returns.
160 .Pp
161 The
162 .Fn callout_init_mtx ,
163 .Fn callout_init_rm ,
164 and
165 .Fn callout_init_rw
166 functions initialize a callout structure in
167 .Fa c
168 that is associated with a specific lock.
169 The lock is specified by the
170 .Fa mtx ,
171 .Fa rm ,
172 or
173 .Fa rw
174 parameter.
175 The associated lock must be held while stopping or rescheduling the
176 callout.
177 The callout subsystem acquires the associated lock before calling the
178 callout function and releases it after the function returns.
179 If the callout was cancelled while the callout subsystem waited for the
180 associated lock,
181 the callout function is not called,
182 and the associated lock is released.
183 This ensures that stopping or rescheduling the callout will abort any
184 previously scheduled invocation.
185 .Pp
186 Only regular mutexes may be used with
187 .Fn callout_init_mtx ;
188 spin mutexes are not supported.
189 A sleepable read-mostly lock
190 .Po
191 one initialized with the
192 .Dv RM_SLEEPABLE
193 flag
194 .Pc
195 may not be used with
196 .Fn callout_init_rm .
197 Similarly, other sleepable lock types such as
198 .Xr sx 9
199 and
200 .Xr lockmgr 9
201 cannot be used with callouts because sleeping is not permitted in
202 the callout subsystem.
203 .Pp
204 These
205 .Fa flags
206 may be specified for
207 .Fn callout_init_mtx ,
208 .Fn callout_init_rm ,
209 or
210 .Fn callout_init_rw :
211 .Bl -tag -width ".Dv CALLOUT_RETURNUNLOCKED"
212 .It Dv CALLOUT_RETURNUNLOCKED
213 The callout function will release the associated lock itself,
214 so the callout subsystem should not attempt to unlock it
215 after the callout function returns.
216 .It Dv CALLOUT_SHAREDLOCK
217 The lock is only acquired in read mode when running the callout handler.
218 This flag is ignored by
219 .Fn callout_init_mtx .
220 .El
221 .Pp
222 The function
223 .Fn callout_stop
224 cancels a callout
225 .Fa c
226 if it is currently pending.
227 If the callout is pending, then
228 .Fn callout_stop
229 returns a non-zero value.
230 If the callout is not set,
231 has already been serviced,
232 or is currently being serviced,
233 then zero will be returned.
234 If the callout has an associated lock,
235 then that lock must be held when this function is called.
236 .Pp
237 The function
238 .Fn callout_drain
239 is identical to
240 .Fn callout_stop
241 except that it will wait for the callout
242 .Fa c
243 to complete if it is already in progress.
244 This function MUST NOT be called while holding any
245 locks on which the callout might block, or deadlock will result.
246 Note that if the callout subsystem has already begun processing this
247 callout, then the callout function may be invoked before
248 .Fn callout_drain
249 returns.
250 However, the callout subsystem does guarantee that the callout will be
251 fully stopped before
252 .Fn callout_drain
253 returns.
254 .Pp
255 The
256 .Fn callout_reset
257 and
258 .Fn callout_schedule
259 function families schedule a future function invocation for callout
260 .Fa c .
261 If
262 .Fa c
263 already has a pending callout,
264 it is cancelled before the new invocation is scheduled.
265 These functions return a non-zero value if a pending callout was cancelled
266 and zero if there was no pending callout.
267 If the callout has an associated lock,
268 then that lock must be held when any of these functions are called.
269 .Pp
270 The time at which the callout function will be invoked is determined by
271 either the
272 .Fa ticks
273 argument or the
274 .Fa sbt ,
275 .Fa pr ,
276 and
277 .Fa flags
278 arguments.
279 When
280 .Fa ticks
281 is used,
282 the callout is scheduled to execute after
283 .Fa ticks Ns No /hz
284 seconds.
285 Non-positive values of
286 .Fa ticks
287 are silently converted to the value
288 .Sq 1 .
289 .Pp
290 The
291 .Fa sbt ,
292 .Fa pr ,
293 and
294 .Fa flags
295 arguments provide more control over the scheduled time including
296 support for higher resolution times,
297 specifying the precision of the scheduled time,
298 and setting an absolute deadline instead of a relative timeout.
299 The callout is scheduled to execute in a time window which begins at
300 the time specified in
301 .Fa sbt
302 and extends for the amount of time specified in
303 .Fa pr .
304 If
305 .Fa sbt
306 specifies a time in the past,
307 the window is adjusted to start at the current time.
308 A non-zero value for
309 .Fa pr
310 allows the callout subsystem to coalesce callouts scheduled close to each
311 other into fewer timer interrupts,
312 reducing processing overhead and power consumption.
313 These
314 .Fa flags
315 may be specified to adjust the interpretation of
316 .Fa sbt
317 and
318 .Fa pr :
319 .Bl -tag -width ".Dv C_DIRECT_EXEC"
320 .It Dv C_ABSOLUTE
321 Handle the
322 .Fa sbt
323 argument as an absolute time since boot.
324 By default,
325 .Fa sbt
326 is treated as a relative amount of time,
327 similar to
328 .Fa ticks .
329 .It Dv C_DIRECT_EXEC
330 Run the handler directly from hardware interrupt context instead of from the
331 softclock thread.
332 This reduces latency and overhead, but puts more constraints on the callout
333 function.
334 Callout functions run in this context may use only spin mutexes for locking
335 and should be as small as possible because they run with absolute priority.
336 .It Fn C_PREL
337 Specifies relative event time precision as binary logarithm of time interval
338 divided by acceptable time deviation: 1 -- 1/2, 2 -- 1/4, etc.
339 Note that the larger of
340 .Fa pr
341 or this value is used as the length of the time window.
342 Smaller values
343 .Pq which result in larger time intervals
344 allow the callout subsystem to aggregate more events in one timer interrupt.
345 .It Dv C_HARDCLOCK
346 Align the timeouts to
347 .Fn hardclock
348 calls if possible.
349 .El
350 .Pp
351 The
352 .Fn callout_reset
353 functions accept a
354 .Fa func
355 argument which identifies the function to be called when the time expires.
356 It must be a pointer to a function that takes a single
357 .Fa void *
358 argument.
359 Upon invocation,
360 .Fa func
361 will receive
362 .Fa arg
363 as its only argument.
364 The
365 .Fn callout_schedule
366 functions reuse the
367 .Fa func
368 and
369 .Fa arg
370 arguments from the previous callout.
371 Note that one of the
372 .Fn callout_reset
373 functions must always be called to initialize
374 .Fa func
375 and
376 .Fa arg
377 before one of the
378 .Fn callout_schedule
379 functions can be used.
380 .Pp
381 The callout subsystem provides a softclock thread for each CPU in the system.
382 Callouts are assigned to a single CPU and are executed by the softclock thread
383 for that CPU.
384 Initially,
385 callouts are assigned to CPU 0.
386 The
387 .Fn callout_reset_on ,
388 .Fn callout_reset_sbt_on ,
389 and
390 .Fn callout_schedule_on
391 functions assign the callout to CPU
392 .Fa cpu .
393 The
394 .Fn callout_reset_curcpu ,
395 .Fn callout_reset_sbt_curpu ,
396 and
397 .Fn callout_schedule_curcpu
398 functions assign the callout to the current CPU.
399 The
400 .Fn callout_reset ,
401 .Fn callout_reset_sbt ,
402 and
403 .Fn callout_schedule
404 functions schedule the callout to execute in the softclock thread of the CPU
405 to which it is currently assigned.
406 .Pp
407 Softclock threads are not pinned to their respective CPUs by default.
408 The softclock thread for CPU 0 can be pinned to CPU 0 by setting the
409 .Va kern.pin_default_swi
410 loader tunable to a non-zero value.
411 Softclock threads for CPUs other than zero can be pinned to their
412 respective CPUs by setting the
413 .Va kern.pin_pcpu_swi
414 loader tunable to a non-zero value.
415 .Pp
416 The macros
417 .Fn callout_pending ,
418 .Fn callout_active
419 and
420 .Fn callout_deactivate
421 provide access to the current state of the callout.
422 The
423 .Fn callout_pending
424 macro checks whether a callout is
425 .Em pending ;
426 a callout is considered
427 .Em pending
428 when a timeout has been set but the time has not yet arrived.
429 Note that once the timeout time arrives and the callout subsystem
430 starts to process this callout,
431 .Fn callout_pending
432 will return
433 .Dv FALSE
434 even though the callout function may not have finished
435 .Pq or even begun
436 executing.
437 The
438 .Fn callout_active
439 macro checks whether a callout is marked as
440 .Em active ,
441 and the
442 .Fn callout_deactivate
443 macro clears the callout's
444 .Em active
445 flag.
446 The callout subsystem marks a callout as
447 .Em active
448 when a timeout is set and it clears the
449 .Em active
450 flag in
451 .Fn callout_stop
452 and
453 .Fn callout_drain ,
454 but it
455 .Em does not
456 clear it when a callout expires normally via the execution of the
457 callout function.
458 .Ss "Avoiding Race Conditions"
459 The callout subsystem invokes callout functions from its own thread
460 context.
461 Without some kind of synchronization,
462 it is possible that a callout
463 function will be invoked concurrently with an attempt to stop or reset
464 the callout by another thread.
465 In particular, since callout functions typically acquire a lock as
466 their first action, the callout function may have already been invoked,
467 but is blocked waiting for that lock at the time that another thread
468 tries to reset or stop the callout.
469 .Pp
470 There are three main techniques for addressing these
471 synchronization concerns.
472 The first approach is preferred as it is the simplest:
473 .Bl -enum -offset indent
474 .It
475 Callouts can be associated with a specific lock when they are initialized
476 by
477 .Fn callout_init_mtx ,
478 .Fn callout_init_rm ,
479 or
480 .Fn callout_init_rw .
481 When a callout is associated with a lock,
482 the callout subsystem acquires the lock before the callout function is
483 invoked.
484 This allows the callout subsystem to transparently handle races between
485 callout cancellation,
486 scheduling,
487 and execution.
488 Note that the associated lock must be acquired before calling
489 .Fn callout_stop
490 or one of the
491 .Fn callout_reset
492 or
493 .Fn callout_schedule
494 functions to provide this safety.
495 .Pp
496 A callout initialized via
497 .Fn callout_init
498 with
499 .Fa mpsafe
500 set to zero is implicitly associated with the
501 .Va Giant
502 mutex.
503 If
504 .Va Giant
505 is held when cancelling or rescheduling the callout,
506 then its use will prevent races with the callout function.
507 .It
508 The return value from
509 .Fn callout_stop
510 .Po
511 or the
512 .Fn callout_reset
513 and
514 .Fn callout_schedule
515 function families
516 .Pc
517 indicates whether or not the callout was removed.
518 If it is known that the callout was set and the callout function has
519 not yet executed, then a return value of
520 .Dv FALSE
521 indicates that the callout function is about to be called.
522 For example:
523 .Bd -literal -offset indent
524 if (sc->sc_flags & SCFLG_CALLOUT_RUNNING) {
525         if (callout_stop(&sc->sc_callout)) {
526                 sc->sc_flags &= ~SCFLG_CALLOUT_RUNNING;
527                 /* successfully stopped */
528         } else {
529                 /*
530                  * callout has expired and callout
531                  * function is about to be executed
532                  */
533         }
534 }
535 .Ed
536 .It
537 The
538 .Fn callout_pending ,
539 .Fn callout_active
540 and
541 .Fn callout_deactivate
542 macros can be used together to work around the race conditions.
543 When a callout's timeout is set, the callout subsystem marks the
544 callout as both
545 .Em active
546 and
547 .Em pending .
548 When the timeout time arrives, the callout subsystem begins processing
549 the callout by first clearing the
550 .Em pending
551 flag.
552 It then invokes the callout function without changing the
553 .Em active
554 flag, and does not clear the
555 .Em active
556 flag even after the callout function returns.
557 The mechanism described here requires the callout function itself to
558 clear the
559 .Em active
560 flag using the
561 .Fn callout_deactivate
562 macro.
563 The
564 .Fn callout_stop
565 and
566 .Fn callout_drain
567 functions always clear both the
568 .Em active
569 and
570 .Em pending
571 flags before returning.
572 .Pp
573 The callout function should first check the
574 .Em pending
575 flag and return without action if
576 .Fn callout_pending
577 returns
578 .Dv TRUE .
579 This indicates that the callout was rescheduled using
580 .Fn callout_reset
581 just before the callout function was invoked.
582 If
583 .Fn callout_active
584 returns
585 .Dv FALSE
586 then the callout function should also return without action.
587 This indicates that the callout has been stopped.
588 Finally, the callout function should call
589 .Fn callout_deactivate
590 to clear the
591 .Em active
592 flag.
593 For example:
594 .Bd -literal -offset indent
595 mtx_lock(&sc->sc_mtx);
596 if (callout_pending(&sc->sc_callout)) {
597         /* callout was reset */
598         mtx_unlock(&sc->sc_mtx);
599         return;
600 }
601 if (!callout_active(&sc->sc_callout)) {
602         /* callout was stopped */
603         mtx_unlock(&sc->sc_mtx);
604         return;
605 }
606 callout_deactivate(&sc->sc_callout);
607 /* rest of callout function */
608 .Ed
609 .Pp
610 Together with appropriate synchronization, such as the mutex used above,
611 this approach permits the
612 .Fn callout_stop
613 and
614 .Fn callout_reset
615 functions to be used at any time without races.
616 For example:
617 .Bd -literal -offset indent
618 mtx_lock(&sc->sc_mtx);
619 callout_stop(&sc->sc_callout);
620 /* The callout is effectively stopped now. */
621 .Ed
622 .Pp
623 If the callout is still pending then these functions operate normally,
624 but if processing of the callout has already begun then the tests in
625 the callout function cause it to return without further action.
626 Synchronization between the callout function and other code ensures that
627 stopping or resetting the callout will never be attempted while the
628 callout function is past the
629 .Fn callout_deactivate
630 call.
631 .Pp
632 The above technique additionally ensures that the
633 .Em active
634 flag always reflects whether the callout is effectively enabled or
635 disabled.
636 If
637 .Fn callout_active
638 returns false, then the callout is effectively disabled, since even if
639 the callout subsystem is actually just about to invoke the callout
640 function, the callout function will return without action.
641 .El
642 .Pp
643 There is one final race condition that must be considered when a
644 callout is being stopped for the last time.
645 In this case it may not be safe to let the callout function itself
646 detect that the callout was stopped, since it may need to access
647 data objects that have already been destroyed or recycled.
648 To ensure that the callout is completely finished, a call to
649 .Fn callout_drain
650 should be used.
651 In particular,
652 a callout should always be drained prior to destroying its associated lock
653 or releasing the storage for the callout structure.
654 .Sh LEGACY API
655 .Bf Sy
656 The functions below are a legacy API that will be removed in a future release.
657 New code should not use these routines.
658 .Ef
659 .Pp
660 The function
661 .Fn timeout
662 schedules a call to the function given by the argument
663 .Fa func
664 to take place after
665 .Fa ticks Ns No /hz
666 seconds.
667 Non-positive values of
668 .Fa ticks
669 are silently converted to the value
670 .Sq 1 .
671 .Fa func
672 should be a pointer to a function that takes a
673 .Fa void *
674 argument.
675 Upon invocation,
676 .Fa func
677 will receive
678 .Fa arg
679 as its only argument.
680 The return value from
681 .Fn timeout
682 is a
683 .Ft struct callout_handle
684 which can be used in conjunction with the
685 .Fn untimeout
686 function to request that a scheduled timeout be canceled.
687 .Pp
688 The function
689 .Fn callout_handle_init
690 can be used to initialize a handle to a state which will cause
691 any calls to
692 .Fn untimeout
693 with that handle to return with no side
694 effects.
695 .Pp
696 Assigning a callout handle the value of
697 .Fn CALLOUT_HANDLE_INITIALIZER
698 performs the same function as
699 .Fn callout_handle_init
700 and is provided for use on statically declared or global callout handles.
701 .Pp
702 The function
703 .Fn untimeout
704 cancels the timeout associated with
705 .Fa handle
706 using the
707 .Fa func
708 and
709 .Fa arg
710 arguments to validate the handle.
711 If the handle does not correspond to a timeout with
712 the function
713 .Fa func
714 taking the argument
715 .Fa arg
716 no action is taken.
717 .Fa handle
718 must be initialized by a previous call to
719 .Fn timeout ,
720 .Fn callout_handle_init ,
721 or assigned the value of
722 .Fn CALLOUT_HANDLE_INITIALIZER "&handle"
723 before being passed to
724 .Fn untimeout .
725 The behavior of calling
726 .Fn untimeout
727 with an uninitialized handle
728 is undefined.
729 .Pp
730 As handles are recycled by the system, it is possible (although unlikely)
731 that a handle from one invocation of
732 .Fn timeout
733 may match the handle of another invocation of
734 .Fn timeout
735 if both calls used the same function pointer and argument, and the first
736 timeout is expired or canceled before the second call.
737 The timeout facility offers O(1) running time for
738 .Fn timeout
739 and
740 .Fn untimeout .
741 Timeouts are executed from
742 .Fn softclock
743 with the
744 .Va Giant
745 lock held.
746 Thus they are protected from re-entrancy.
747 .Sh RETURN VALUES
748 The
749 .Fn callout_active
750 macro returns the state of a callout's
751 .Em active
752 flag.
753 .Pp
754 The
755 .Fn callout_pending
756 macro returns the state of a callout's
757 .Em pending
758 flag.
759 .Pp
760 The
761 .Fn callout_reset
762 and
763 .Fn callout_schedule
764 function families return non-zero if the callout was pending before the new
765 function invocation was scheduled.
766 .Pp
767 The
768 .Fn callout_stop
769 and
770 .Fn callout_drain
771 functions return non-zero if the callout was still pending when it was
772 called or zero otherwise.
773 The
774 .Fn timeout
775 function returns a
776 .Ft struct callout_handle
777 that can be passed to
778 .Fn untimeout .
779 .Sh HISTORY
780 The current timeout and untimeout routines are based on the work of
781 .An Adam M. Costello
782 and
783 .An George Varghese ,
784 published in a technical report entitled
785 .%T "Redesigning the BSD Callout and Timer Facilities"
786 and modified slightly for inclusion in
787 .Fx
788 by
789 .An Justin T. Gibbs .
790 The original work on the data structures used in this implementation
791 was published by
792 .An G. Varghese
793 and
794 .An A. Lauck
795 in the paper
796 .%T "Hashed and Hierarchical Timing Wheels: Data Structures for the Efficient Implementation of a Timer Facility"
797 in the
798 .%B "Proceedings of the 11th ACM Annual Symposium on Operating Systems Principles" .
799 The current implementation replaces the long standing
800 .Bx
801 linked list
802 callout mechanism which offered O(n) insertion and removal running time
803 but did not generate or require handles for untimeout operations.