nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man9f / untimeout.9f
blob7c169e962b158f2af950ed9fea7643bc5c248450
1 '\" te
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"
9 .SH NAME
10 untimeout \- cancel previous timeout function call
11 .SH SYNOPSIS
12 .LP
13 .nf
14 #include <sys/types.h>
15 #include <sys/conf.h>
19 \fBclock_t\fR \fBuntimeout\fR(\fBtimeout_id_t\fR \fIid\fR);
20 .fi
22 .SH INTERFACE LEVEL
23 .sp
24 .LP
25 Architecture independent level 1 (DDI/DKI).
26 .SH PARAMETERS
27 .sp
28 .ne 2
29 .na
30 \fB\fIid\fR\fR
31 .ad
32 .RS 6n
33 Opaque timeout \fBID\fR from a previous \fBtimeout\fR(9F) call.
34 .RE
36 .SH DESCRIPTION
37 .sp
38 .LP
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.
43 .sp
44 .LP
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.
52 .SH RETURN VALUES
53 .sp
54 .LP
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.
57 .SH CONTEXT
58 .sp
59 .LP
60 The \fBuntimeout()\fR function can be called from user, interrupt, or kernel
61 context.
62 .SH EXAMPLES
63 .sp
64 .LP
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.
68 .sp
69 .in +2
70 .nf
71 static void
72 xxtimeout_handler(void *arg)
74         struct xxstate *xsp = (struct xxstate *)arg;
75         mutex_enter(&xsp->lock);
76         cv_signal(&xsp->cv);
77         xsp->flags |= TIMED_OUT;
78         mutex_exit(&xsp->lock);
79         xsp->timeout_id = 0;
81 static uint_t
82 xxintr(caddr_t arg)
84         struct xxstate *xsp = (struct xxstate *)arg;
85          .
86          .
87          .
88         mutex_enter(&xsp->lock);
89         /* Service interrupt */
90         cv_signal(&xsp->cv);
91         mutex_exit(&xsp->lock);
92         if (xsp->timeout_id != 0) {
93                 (void) untimeout(xsp->timeout_id);
94                 xsp->timeout_id = 0;
95         }
96         return(DDI_INTR_CLAIMED);
98 static void
99 xxcheckcond(struct xxstate *xsp)
101          .
102          .
103          .
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");
111          .
112          .
113          .
114         mutex_exit(&xsp->lock);
115          .
116          .
117          .
120 .in -2
122 .SH SEE ALSO
125 \fBopen\fR(9E), \fBcv_signal\fR(9F), \fBcv_wait_sig\fR(9F), \fBdelay\fR(9F),
126 \fBtimeout\fR(9F)
129 \fIWriting Device Drivers\fR