xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_timerq.h (revision 2a8bcb4e)
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 #include <pthread.h>
31 #include <time.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <fmd_idspace.h>
38 #include <fmd_thread.h>
39 #include <fmd_event.h>
40 #include <fmd_list.h>
41 
42 typedef void fmd_timer_f(void *, id_t, hrtime_t);
43 
44 typedef struct fmd_timer {
45 	fmd_list_t tmr_list;	/* expiry or free list next/prev pointers */
46 	hrtime_t tmr_hrt;	/* high-res time at which timer should fire */
47 	fmd_idspace_t *tmr_ids;	/* idspace that contains the timer id */
48 	id_t tmr_id;		/* client identifier for this timer */
49 	fmd_timer_f *tmr_func;	/* function that should be called on expiry */
50 	void *tmr_arg;		/* argument to pass back to tmr_func */
51 	pthread_cond_t tmr_cv;	/* condition variable for waiting on tmr_func */
52 } fmd_timer_t;
53 
54 typedef struct fmd_timerq {
55 	fmd_thread_t *tmq_thread; /* thread handling timer expiry for queue */
56 	uint_t tmq_abort;	/* flag indicating tmq_thread should abort */
57 	pthread_mutex_t tmq_lock; /* lock protecting timer queue contents */
58 	pthread_cond_t tmq_cv;	/* condition variable for tmq_list, abort */
59 	fmd_list_t tmq_list;	/* list of active timers, sorted by tmr_hrt */
60 	fmd_list_t tmq_free;	/* list of free timers */
61 } fmd_timerq_t;
62 
63 extern id_t fmd_timerq_install(fmd_timerq_t *,
64     fmd_idspace_t *, fmd_timer_f *, void *, fmd_event_t *, hrtime_t);
65 
66 extern void *fmd_timerq_remove(fmd_timerq_t *, fmd_idspace_t *, id_t);
67 extern fmd_timerq_t *fmd_timerq_create(void);
68 extern void fmd_timerq_destroy(fmd_timerq_t *);
69 
70 #ifdef	__cplusplus
71 }
72 #endif
73 
74 #endif	/* _FMD_TIMERQ_H */
75