#include <sys/types.h> #include <sys/conf.h> int timeout(void (*func)(caddr_t), caddr_t arg, long ticks);
Architecture independent level 1 (DDI/DKI).
The function called by timeout() must adhere to the same restrictions as a driver soft interrupt handler.
The timeout() function returns an identifier that may be passed to the untimeout(9F) function to cancel a pending request.
PANIC: Timeout table overflow
timeout() can be called from user or interrupt context.
In the following example, the device driver has issued an IO request and is waiting for the device to respond. If the device does not respond within 5 minutes, the device driver will print out an error message to the console.
static void xxtimeout_handler(caddr_t arg) { struct xxstate *xsp = (struct xxstate *)arg; mutex_enter(&xsp->lock); cv_signal(&xsp->cv); xsp->timeout_id = 0; xsp->flags |= TIMED_OUT; mutex_exit(&xsp->lock); } static u_int xxintr(caddr_t arg) { struct xxstate *xsp = (struct xxstate *)arg; . . . mutex_enter(&xsp->lock); if (xsp->timeout_id != 0) { (void) untimeout(xsp->timeout_id); xsp->timeout_id = 0; } /* Service interrupt */ cv_signal(&xsp->cv); mutex_exit(&xsp->lock); return(DDI_INTR_CLAIMED); } static void xxcheckcond(struct xxstate *xsp) { . . . mutex_enter(&xsp->lock); xsp->timeout_id = timeout(xxtimeout_handler, (caddr_t)xsp, (5 * drv_usectohz(1000000)); while (/* Waiting for interrupt or timeout*/) cv_wait(&xsp->cv, &xsp->lock); if (xsp->flags & TIMED_OUT) cmn_err(CE_WARN, "Device not responding"); . . . mutex_exit(&xsp->lock); . . . }