2 .\" Copyright 2014 Nexenta Systems, Inc. All rights reserved.
3 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Copyright 1989 AT&T
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH UNTIMEOUT 9F "Feb 12, 2014"
10 untimeout \- cancel previous timeout function call
14 #include <sys/types.h>
19 \fBclock_t\fR \fBuntimeout\fR(\fBtimeout_id_t\fR \fIid\fR);
25 Architecture independent level 1 (DDI/DKI).
33 Opaque timeout \fBID\fR from a previous \fBtimeout\fR(9F) call.
39 The \fBuntimeout()\fR function cancels a pending \fBtimeout\fR(9F) request.
40 \fBuntimeout()\fR will not return until the pending callback is cancelled or
41 has run. Because of this, locks acquired by the callback routine must not be
42 held across the call to \fBuntimeout()\fR or a deadlock may result.
45 Since no mutex should be held across the call to \fBuntimeout()\fR, there is a
46 race condition between the occurrence of an expected event and the execution of
47 the timeout handler. In particular, it should be noted that no problems will
48 result from calling \fBuntimeout()\fR for a timeout which is either running on
49 another CPU, or has already completed. Drivers should be structured with the
50 understanding that the arrival of both an interrupt and a timeout for that
51 interrupt can occasionally occur, in either order.
55 The \fBuntimeout()\fR function returns \fB-1\fR if the \fIid\fR is not found.
56 Otherwise, it returns an integer value greater than or equal to \fB0\fR.
60 The \fBuntimeout()\fR function can be called from user, interrupt, or kernel
65 In the following example, the device driver has issued an IO request and is
66 waiting for the device to respond. If the device does not respond within 5
67 seconds, the device driver will print out an error message to the console.
72 xxtimeout_handler(void *arg)
74 struct xxstate *xsp = (struct xxstate *)arg;
75 mutex_enter(&xsp->lock);
77 xsp->flags |= TIMED_OUT;
78 mutex_exit(&xsp->lock);
84 struct xxstate *xsp = (struct xxstate *)arg;
88 mutex_enter(&xsp->lock);
89 /* Service interrupt */
91 mutex_exit(&xsp->lock);
92 if (xsp->timeout_id != 0) {
93 (void) untimeout(xsp->timeout_id);
96 return(DDI_INTR_CLAIMED);
99 xxcheckcond(struct xxstate *xsp)
104 xsp->timeout_id = timeout(xxtimeout_handler,
105 xsp, (5 * drv_usectohz(1000000)));
106 mutex_enter(&xsp->lock);
107 while (/* Waiting for interrupt or timeout*/)
108 cv_wait(&xsp->cv, &xsp->lock);
109 if (xsp->flags & TIMED_OUT)
110 cmn_err(CE_WARN, "Device not responding");
114 mutex_exit(&xsp->lock);
125 \fBopen\fR(9E), \fBcv_signal\fR(9F), \fBcv_wait_sig\fR(9F), \fBdelay\fR(9F),
129 \fIWriting Device Drivers\fR