CALLOUT(9) NetBSD Kernel Manual CALLOUT(9)
NAME
callout_init, callout_reset, callout_stop - execute a function after a specified length of time
SYNOPSIS
#include <sys/callout.h> void callout_init(struct callout *c); void callout_reset(struct callout *c, int ticks, void (*func)(void *), void *arg); void callout_stop(struct callout *c); int callout_active(struct callout *c); int callout_pending(struct callout *c); int callout_expired(struct callout *c); void callout_deactivate(struct callout *c);
DESCRIPTION
The callout facility provides a mechanism to execute a function at a giv- en time. The timer is based on the hardclock timer which ticks hz times per second. The function is called at softclock interrupt level. Clients of the callout facility are responsible for providing pre-allo- cated callout structures, or ``handles''. The callout facility replaces the historic BSD functions timeout() and untimeout(). The callout_init() function initializes the callout handle c for use. If it is inconvenient to call callout_init(), statically-allocated callout handles may be initialized by assigning the value CALLOUT_INITIALIZER to them. The callout_reset() function starts (or resets) the timer associated with the callout handle c. When the timer expires after ticks/hz seconds, the function specified by func will be called with the argument arg. Note that if the timer associated with the callout handle is already running, it will be implicitly stopped before being reset. Once the timer is started, the callout handle is marked as ACTIVE and PENDING. Once the timer expires, PENDING status is cleared. Expiration of the timer does not affect ACTIVE status. The callout_stop() function stops the timer associated the callout handle c. The ACTIVE and PENDING status for the callout handle is cleared. It is safe to call callout_stop() on a callout handle that is not active, so long as it is initialized. The callout_active() function tests the ACTIVE status of the callout han- dle c. An ACTIVE callout is one that has been started but not explicitly stopped. Testing ACTIVE status is a way to determine if a callout has been started. Once the callout fires, the executed function may clear ACTIVE status. See callout_deactivate() below. The callout_pending() function tests the PENDING status of the callout handle c. A PENDING callout is one that has been started and whose func- tion has not yet been called. Note that it is possible for a callout's timer to have expired without its function being called if interrupt lev- el has not dropped low enough to let softclock interrupts through. Note that it is only safe to test PENDING status when at softclock interrupt level or higher. The callout_expired() function tests the opposite of callout_pending(). That is to say that callout_expired() returns true when the callout func- tion has been called. The callout_deactivate() function clears the ACTIVE status of the callout handle c. Note that is only safe to call callout_deactivate() if the callout function has already been executed, i.e. the callout is no longer PENDING.
SEE ALSO
hz(9)
HISTORY
The callout facility is based on the work of Adam M. Costello and George Varghese, published in a technical report entitled ``Redesigning the BSD Callout and Timer Facilities'', and Justin Gibbs's subsequent integration into FreeBSD. It was modified for NetBSD by Jason R. Thorpe, who also added optional statistics gathering and an alternate sorting mode for the callwheel. The original work on the data structures used in this implementation was published by G. Varghese and A. Lauck in the paper Hashed and Hierarchi- cal Timing Wheels: Data Structures for the Efficient Implementation of a Timer Facility in the Proceedings of the 11th ACM Annual Symposium on Op- erating System Principles, Austin, Texas, November 1987. NetBSD 1.6 March 21, 2000 2
Powered by man-cgi (2024-08-26). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.