xref: /titanic_52/usr/src/cmd/fm/fmd/common/fmd_timerq.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <signal.h>
30*7c478bd9Sstevel@tonic-gate #include <strings.h>
31*7c478bd9Sstevel@tonic-gate #include <limits.h>
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <fmd_alloc.h>
34*7c478bd9Sstevel@tonic-gate #include <fmd_subr.h>
35*7c478bd9Sstevel@tonic-gate #include <fmd_thread.h>
36*7c478bd9Sstevel@tonic-gate #include <fmd_timerq.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <fmd.h>
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * Install a new timer to fire after at least 'delta' nanoseconds have elapsed.
42*7c478bd9Sstevel@tonic-gate  * Timers are associated with persistent integer identifiers in some idspace.
43*7c478bd9Sstevel@tonic-gate  * We allocate a new timer structure or re-use one from our freelist, and then
44*7c478bd9Sstevel@tonic-gate  * place it on the queue's list in sorted order by expiration time.  If the new
45*7c478bd9Sstevel@tonic-gate  * timer is now the earliest to expire, we awaken the fmd_timerq_exec() thread.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate id_t
48*7c478bd9Sstevel@tonic-gate fmd_timerq_install(fmd_timerq_t *tmq, fmd_idspace_t *ids,
49*7c478bd9Sstevel@tonic-gate     fmd_timer_f *func, void *arg, fmd_event_t *ep, hrtime_t delta)
50*7c478bd9Sstevel@tonic-gate {
51*7c478bd9Sstevel@tonic-gate 	hrtime_t now = fmd_time_gethrtime();
52*7c478bd9Sstevel@tonic-gate 	hrtime_t base = ep ? fmd_event_hrtime(ep) : now;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	fmd_timer_t *tp, *up;
55*7c478bd9Sstevel@tonic-gate 	hrtime_t hrt;
56*7c478bd9Sstevel@tonic-gate 	id_t id;
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&tmq->tmq_lock);
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	if ((tp = fmd_list_next(&tmq->tmq_free)) == NULL) {
61*7c478bd9Sstevel@tonic-gate 		tp = fmd_zalloc(sizeof (fmd_timer_t), FMD_SLEEP);
62*7c478bd9Sstevel@tonic-gate 		(void) pthread_cond_init(&tp->tmr_cv, NULL);
63*7c478bd9Sstevel@tonic-gate 	} else
64*7c478bd9Sstevel@tonic-gate 		fmd_list_delete(&tmq->tmq_free, tp);
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 	if ((id = fmd_idspace_alloc(ids, tp)) == -1) {
67*7c478bd9Sstevel@tonic-gate 		fmd_list_prepend(&tmq->tmq_free, tp);
68*7c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&tmq->tmq_lock);
69*7c478bd9Sstevel@tonic-gate 		return (id);
70*7c478bd9Sstevel@tonic-gate 	}
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	if (delta < 0)
73*7c478bd9Sstevel@tonic-gate 		delta = 0; /* ensure delta is at least 0ns from now */
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	if (base + delta < base)
76*7c478bd9Sstevel@tonic-gate 		hrt = INT64_MAX; /* if wrap-around, set timer for apocalypse */
77*7c478bd9Sstevel@tonic-gate 	else
78*7c478bd9Sstevel@tonic-gate 		hrt = base + delta;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	tp->tmr_hrt = hrt;
81*7c478bd9Sstevel@tonic-gate 	tp->tmr_ids = ids;
82*7c478bd9Sstevel@tonic-gate 	tp->tmr_id = id;
83*7c478bd9Sstevel@tonic-gate 	tp->tmr_func = func;
84*7c478bd9Sstevel@tonic-gate 	tp->tmr_arg = arg;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	/*
87*7c478bd9Sstevel@tonic-gate 	 * For now we use a simple insertion sort for tmq_list.  If we have
88*7c478bd9Sstevel@tonic-gate 	 * scaling problems here due to heavy use of our timer subsystem,
89*7c478bd9Sstevel@tonic-gate 	 * then tmq_list can and should be replaced with a O(logN) heap.
90*7c478bd9Sstevel@tonic-gate 	 */
91*7c478bd9Sstevel@tonic-gate 	for (up = fmd_list_next(&tmq->tmq_list); up; up = fmd_list_next(up)) {
92*7c478bd9Sstevel@tonic-gate 		if (tp->tmr_hrt < up->tmr_hrt)
93*7c478bd9Sstevel@tonic-gate 			break;
94*7c478bd9Sstevel@tonic-gate 	}
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	if (up != NULL)
97*7c478bd9Sstevel@tonic-gate 		fmd_list_insert_before(&tmq->tmq_list, up, tp);
98*7c478bd9Sstevel@tonic-gate 	else
99*7c478bd9Sstevel@tonic-gate 		fmd_list_insert_after(&tmq->tmq_list, up, tp);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 	if (up != NULL && fmd_list_next(&tmq->tmq_list) == tp)
102*7c478bd9Sstevel@tonic-gate 		fmd_time_waitcancel(tmq->tmq_thread->thr_tid);
103*7c478bd9Sstevel@tonic-gate 	else if (up == NULL && fmd_list_next(&tmq->tmq_list) == tp)
104*7c478bd9Sstevel@tonic-gate 		(void) pthread_cond_signal(&tmq->tmq_cv);
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&tmq->tmq_lock);
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	TRACE((FMD_DBG_TMR, "timer %s:%ld insert +%lldns",
109*7c478bd9Sstevel@tonic-gate 	    ids->ids_name, id, delta));
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	return (id);
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /*
115*7c478bd9Sstevel@tonic-gate  * Remove the specified timer.  If the 'id' is invalid, we'll panic inside of
116*7c478bd9Sstevel@tonic-gate  * fmd_idspace_free().  If the timer is still set, we move it to the freelist
117*7c478bd9Sstevel@tonic-gate  * and update the timer thread as needed.  If the timer 'id' is valid but
118*7c478bd9Sstevel@tonic-gate  * tmr_id is not equal to id, then the timer callback is running: we wait for
119*7c478bd9Sstevel@tonic-gate  * tmr_id to change to zero (indicating tmr_func is done) before returning.
120*7c478bd9Sstevel@tonic-gate  */
121*7c478bd9Sstevel@tonic-gate void *
122*7c478bd9Sstevel@tonic-gate fmd_timerq_remove(fmd_timerq_t *tmq, fmd_idspace_t *ids, id_t id)
123*7c478bd9Sstevel@tonic-gate {
124*7c478bd9Sstevel@tonic-gate 	hrtime_t delta = 0;
125*7c478bd9Sstevel@tonic-gate 	void *arg = NULL;
126*7c478bd9Sstevel@tonic-gate 	fmd_timer_t *tp;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&tmq->tmq_lock);
129*7c478bd9Sstevel@tonic-gate 	tp = fmd_idspace_free(ids, id);
130*7c478bd9Sstevel@tonic-gate 	ASSERT(tp == NULL || tp->tmr_ids == ids);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	if (tp == NULL) {
133*7c478bd9Sstevel@tonic-gate 		(void) pthread_mutex_unlock(&tmq->tmq_lock);
134*7c478bd9Sstevel@tonic-gate 		return (NULL); /* timer is no longer active */
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	if (tp->tmr_id == id) {
138*7c478bd9Sstevel@tonic-gate 		fmd_list_delete(&tmq->tmq_list, tp);
139*7c478bd9Sstevel@tonic-gate 		delta = tp->tmr_hrt - fmd_time_gethrtime();
140*7c478bd9Sstevel@tonic-gate 		arg = tp->tmr_arg;
141*7c478bd9Sstevel@tonic-gate 		tp->tmr_id = 0;
142*7c478bd9Sstevel@tonic-gate 		fmd_list_append(&tmq->tmq_free, tp);
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 		/*
145*7c478bd9Sstevel@tonic-gate 		 * If tmq_list is now empty, we must awaken the exec thread so
146*7c478bd9Sstevel@tonic-gate 		 * it will sleep on tmq_cv waiting for the list to change.  We
147*7c478bd9Sstevel@tonic-gate 		 * could also awaken the exec thread if we removed the head of
148*7c478bd9Sstevel@tonic-gate 		 * tmq_list, but an early wakeup is harmless so we do nothing.
149*7c478bd9Sstevel@tonic-gate 		 */
150*7c478bd9Sstevel@tonic-gate 		if (fmd_list_next(&tmq->tmq_list) == NULL)
151*7c478bd9Sstevel@tonic-gate 			fmd_time_waitcancel(tmq->tmq_thread->thr_tid);
152*7c478bd9Sstevel@tonic-gate 	} else {
153*7c478bd9Sstevel@tonic-gate 		/*
154*7c478bd9Sstevel@tonic-gate 		 * Wait until tmr_id is zero, indicating that tmr_func is done.
155*7c478bd9Sstevel@tonic-gate 		 * This relies on expired fmd_timer_t's being returned to our
156*7c478bd9Sstevel@tonic-gate 		 * free list rather than having the data structure deallocated.
157*7c478bd9Sstevel@tonic-gate 		 */
158*7c478bd9Sstevel@tonic-gate 		while (tp->tmr_id != 0)
159*7c478bd9Sstevel@tonic-gate 			(void) pthread_cond_wait(&tp->tmr_cv, &tmq->tmq_lock);
160*7c478bd9Sstevel@tonic-gate 	}
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&tmq->tmq_lock);
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	TRACE((FMD_DBG_TMR, "timer %s:%ld remove -%lldns",
165*7c478bd9Sstevel@tonic-gate 	    ids->ids_name, id, delta > 0 ? delta : 0LL));
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	return (arg);
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * fmd_timerq_exec() is the main loop of the thread that runs the timer queue.
172*7c478bd9Sstevel@tonic-gate  * We sleep on tmq_cv waiting for timers to show up on tmq_list.  When the list
173*7c478bd9Sstevel@tonic-gate  * is non-empty, we execute the callback function for each expired timer.  If
174*7c478bd9Sstevel@tonic-gate  * timers remain that are not yet expired, we nanosleep() until the next expiry
175*7c478bd9Sstevel@tonic-gate  * time.  We awaken whenever nanosleep() expires or we are interrupted by a
176*7c478bd9Sstevel@tonic-gate  * SIGALRM from fmd_timerq_install indicating that we need to rescan our list.
177*7c478bd9Sstevel@tonic-gate  */
178*7c478bd9Sstevel@tonic-gate static void
179*7c478bd9Sstevel@tonic-gate fmd_timerq_exec(fmd_timerq_t *tmq)
180*7c478bd9Sstevel@tonic-gate {
181*7c478bd9Sstevel@tonic-gate 	fmd_timer_t *tp;
182*7c478bd9Sstevel@tonic-gate 	sigset_t set;
183*7c478bd9Sstevel@tonic-gate 	hrtime_t now;
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate 	/*
186*7c478bd9Sstevel@tonic-gate 	 * fmd_thread_create() initializes threads with all signals blocked.
187*7c478bd9Sstevel@tonic-gate 	 * We must unblock SIGALRM (whose disposition has been to set to call
188*7c478bd9Sstevel@tonic-gate 	 * an empty function by fmd_timerq_init()) in order to permit directed
189*7c478bd9Sstevel@tonic-gate 	 * signals to interrupt our nanosleep() and make it return EINTR.
190*7c478bd9Sstevel@tonic-gate 	 * This SIGALRM mechanism is used by the native clock (see fmd_time.c).
191*7c478bd9Sstevel@tonic-gate 	 */
192*7c478bd9Sstevel@tonic-gate 	(void) sigemptyset(&set);
193*7c478bd9Sstevel@tonic-gate 	(void) sigaddset(&set, SIGALRM);
194*7c478bd9Sstevel@tonic-gate 	(void) pthread_sigmask(SIG_UNBLOCK, &set, NULL);
195*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&tmq->tmq_lock);
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	for (;;) {
198*7c478bd9Sstevel@tonic-gate 		while (!tmq->tmq_abort && fmd_list_next(&tmq->tmq_list) == NULL)
199*7c478bd9Sstevel@tonic-gate 			(void) pthread_cond_wait(&tmq->tmq_cv, &tmq->tmq_lock);
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 		if (tmq->tmq_abort) {
202*7c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&tmq->tmq_lock);
203*7c478bd9Sstevel@tonic-gate 			return; /* abort timerq thread */
204*7c478bd9Sstevel@tonic-gate 		}
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 		for (now = fmd_time_gethrtime(); (tp = fmd_list_next(
207*7c478bd9Sstevel@tonic-gate 		    &tmq->tmq_list)) != NULL; now = fmd_time_gethrtime()) {
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 			if (now == INT64_MAX || tp->tmr_hrt > now)
210*7c478bd9Sstevel@tonic-gate 				break; /* no more timers left to expire */
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 			tp->tmr_id = -tp->tmr_id;
213*7c478bd9Sstevel@tonic-gate 			fmd_list_delete(&tmq->tmq_list, tp);
214*7c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&tmq->tmq_lock);
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 			TRACE((FMD_DBG_TMR, "tmr %s:%ld exec start (hrt=%llx)",
217*7c478bd9Sstevel@tonic-gate 			    tp->tmr_ids->ids_name, -tp->tmr_id, tp->tmr_hrt));
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 			tp->tmr_func(tp->tmr_arg, -tp->tmr_id, tp->tmr_hrt);
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 			TRACE((FMD_DBG_TMR, "tmr %s:%ld exec end",
222*7c478bd9Sstevel@tonic-gate 			    tp->tmr_ids->ids_name, -tp->tmr_id));
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_lock(&tmq->tmq_lock);
225*7c478bd9Sstevel@tonic-gate 			(void) fmd_idspace_free(tp->tmr_ids, -tp->tmr_id);
226*7c478bd9Sstevel@tonic-gate 			fmd_list_append(&tmq->tmq_free, tp);
227*7c478bd9Sstevel@tonic-gate 			tp->tmr_id = 0; /* for fmd_timer_remove() */
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 			(void) pthread_cond_broadcast(&tp->tmr_cv);
230*7c478bd9Sstevel@tonic-gate 		}
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 		if (tp != NULL) {
233*7c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_unlock(&tmq->tmq_lock);
234*7c478bd9Sstevel@tonic-gate 			fmd_time_waithrtime(tp->tmr_hrt - now);
235*7c478bd9Sstevel@tonic-gate 			(void) pthread_mutex_lock(&tmq->tmq_lock);
236*7c478bd9Sstevel@tonic-gate 		}
237*7c478bd9Sstevel@tonic-gate 	}
238*7c478bd9Sstevel@tonic-gate }
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate static void
241*7c478bd9Sstevel@tonic-gate fmd_timerq_alrm(int sig)
242*7c478bd9Sstevel@tonic-gate {
243*7c478bd9Sstevel@tonic-gate 	TRACE((FMD_DBG_TMR, "timer thread received alarm sig#%d", sig));
244*7c478bd9Sstevel@tonic-gate }
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate fmd_timerq_t *
247*7c478bd9Sstevel@tonic-gate fmd_timerq_create(void)
248*7c478bd9Sstevel@tonic-gate {
249*7c478bd9Sstevel@tonic-gate 	fmd_timerq_t *tmq = fmd_zalloc(sizeof (fmd_timerq_t), FMD_SLEEP);
250*7c478bd9Sstevel@tonic-gate 	struct sigaction act;
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_init(&tmq->tmq_lock, NULL);
253*7c478bd9Sstevel@tonic-gate 	(void) pthread_cond_init(&tmq->tmq_cv, NULL);
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	act.sa_handler = fmd_timerq_alrm;
256*7c478bd9Sstevel@tonic-gate 	act.sa_flags = 0;
257*7c478bd9Sstevel@tonic-gate 	(void) sigemptyset(&act.sa_mask);
258*7c478bd9Sstevel@tonic-gate 	(void) sigaction(SIGALRM, &act, NULL);
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 	if ((tmq->tmq_thread = fmd_thread_create(fmd.d_rmod,
261*7c478bd9Sstevel@tonic-gate 	    (fmd_thread_f *)fmd_timerq_exec, tmq)) == NULL)
262*7c478bd9Sstevel@tonic-gate 		fmd_panic("failed to create timer thread");
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 	return (tmq);
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate void
268*7c478bd9Sstevel@tonic-gate fmd_timerq_destroy(fmd_timerq_t *tmq)
269*7c478bd9Sstevel@tonic-gate {
270*7c478bd9Sstevel@tonic-gate 	struct sigaction act;
271*7c478bd9Sstevel@tonic-gate 	fmd_timer_t *tmr;
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&tmq->tmq_lock);
274*7c478bd9Sstevel@tonic-gate 	tmq->tmq_abort++;
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate 	if (fmd_list_next(&tmq->tmq_list) != NULL)
277*7c478bd9Sstevel@tonic-gate 		fmd_time_waitcancel(tmq->tmq_thread->thr_tid);
278*7c478bd9Sstevel@tonic-gate 	else
279*7c478bd9Sstevel@tonic-gate 		(void) pthread_cond_signal(&tmq->tmq_cv);
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_unlock(&tmq->tmq_lock);
282*7c478bd9Sstevel@tonic-gate 	fmd_thread_destroy(tmq->tmq_thread, FMD_THREAD_JOIN);
283*7c478bd9Sstevel@tonic-gate 	(void) pthread_mutex_lock(&tmq->tmq_lock);
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 	while ((tmr = fmd_list_next(&tmq->tmq_list)) != NULL) {
286*7c478bd9Sstevel@tonic-gate 		fmd_list_delete(&tmq->tmq_list, tmr);
287*7c478bd9Sstevel@tonic-gate 		(void) fmd_idspace_free(tmr->tmr_ids, tmr->tmr_id);
288*7c478bd9Sstevel@tonic-gate 		fmd_free(tmr, sizeof (fmd_timer_t));
289*7c478bd9Sstevel@tonic-gate 	}
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 	while ((tmr = fmd_list_next(&tmq->tmq_free)) != NULL) {
292*7c478bd9Sstevel@tonic-gate 		fmd_list_delete(&tmq->tmq_free, tmr);
293*7c478bd9Sstevel@tonic-gate 		ASSERT(tmr->tmr_id == 0);
294*7c478bd9Sstevel@tonic-gate 		fmd_free(tmr, sizeof (fmd_timer_t));
295*7c478bd9Sstevel@tonic-gate 	}
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	act.sa_handler = SIG_DFL;
298*7c478bd9Sstevel@tonic-gate 	act.sa_flags = 0;
299*7c478bd9Sstevel@tonic-gate 	(void) sigemptyset(&act.sa_mask);
300*7c478bd9Sstevel@tonic-gate 	(void) sigaction(SIGALRM, &act, NULL);
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate 	fmd_free(tmq, sizeof (fmd_timerq_t));
303*7c478bd9Sstevel@tonic-gate }
304