xref: /titanic_41/usr/src/cmd/fm/fmd/common/fmd_timerq.h (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_TIMERQ_H
28 #define	_FMD_TIMERQ_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <pthread.h>
33 #include <time.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <fmd_idspace.h>
40 #include <fmd_thread.h>
41 #include <fmd_event.h>
42 #include <fmd_list.h>
43 
44 typedef void fmd_timer_f(void *, id_t, hrtime_t);
45 
46 typedef struct fmd_timer {
47 	fmd_list_t tmr_list;	/* expiry or free list next/prev pointers */
48 	hrtime_t tmr_hrt;	/* high-res time at which timer should fire */
49 	fmd_idspace_t *tmr_ids;	/* idspace that contains the timer id */
50 	id_t tmr_id;		/* client identifier for this timer */
51 	fmd_timer_f *tmr_func;	/* function that should be called on expiry */
52 	void *tmr_arg;		/* argument to pass back to tmr_func */
53 	pthread_cond_t tmr_cv;	/* condition variable for waiting on tmr_func */
54 } fmd_timer_t;
55 
56 typedef struct fmd_timerq {
57 	fmd_thread_t *tmq_thread; /* thread handling timer expiry for queue */
58 	uint_t tmq_abort;	/* flag indicating tmq_thread should abort */
59 	pthread_mutex_t tmq_lock; /* lock protecting timer queue contents */
60 	pthread_cond_t tmq_cv;	/* condition variable for tmq_list, abort */
61 	fmd_list_t tmq_list;	/* list of active timers, sorted by tmr_hrt */
62 	fmd_list_t tmq_free;	/* list of free timers */
63 } fmd_timerq_t;
64 
65 extern id_t fmd_timerq_install(fmd_timerq_t *,
66     fmd_idspace_t *, fmd_timer_f *, void *, fmd_event_t *, hrtime_t);
67 
68 extern void *fmd_timerq_remove(fmd_timerq_t *, fmd_idspace_t *, id_t);
69 extern fmd_timerq_t *fmd_timerq_create(void);
70 extern void fmd_timerq_destroy(fmd_timerq_t *);
71 
72 #ifdef	__cplusplus
73 }
74 #endif
75 
76 #endif	/* _FMD_TIMERQ_H */
77