xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_eventq.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_EVENTQ_H
28 #define	_FMD_EVENTQ_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <pthread.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <fmd_event.h>
39 #include <fmd_list.h>
40 
41 typedef struct fmd_eventqstat {
42 	fmd_stat_t eqs_dispatched;	/* total events dispatched to queue */
43 	fmd_stat_t eqs_dequeued;	/* total events dequeued by consumer */
44 	fmd_stat_t eqs_prdequeued;	/* total protocol events dequeued */
45 	fmd_stat_t eqs_dropped;		/* total events dropped by queue */
46 	fmd_stat_t eqs_wcnt;		/* count of events waiting on queue */
47 	fmd_stat_t eqs_wtime;		/* total wait time (pre-dispatch) */
48 	fmd_stat_t eqs_wlentime;	/* total wait length * time product */
49 	fmd_stat_t eqs_wlastupdate;	/* hrtime of last wait queue update */
50 	fmd_stat_t eqs_dtime;		/* total dispatch time */
51 	fmd_stat_t eqs_dlastupdate;	/* hrtime of last dispatch */
52 } fmd_eventqstat_t;
53 
54 typedef struct fmd_eventqelem {
55 	fmd_list_t eqe_list;		/* linked-list prev/next pointers */
56 	fmd_event_t *eqe_event;		/* pointer to event */
57 } fmd_eventqelem_t;
58 
59 struct fmd_module;			/* see <fmd_module.h> */
60 
61 typedef struct fmd_eventq {
62 	pthread_mutex_t eq_lock;	/* lock protecting queue contents */
63 	pthread_cond_t eq_cv;		/* condition variable for waiters */
64 	fmd_list_t eq_list;		/* list head/tail pointers for queue */
65 	struct fmd_module *eq_mod;	/* module associated with this queue */
66 	pthread_mutex_t *eq_stats_lock;	/* lock that protects eq_stats */
67 	fmd_eventqstat_t *eq_stats;	/* statistics associated with queue */
68 	uint_t eq_limit;		/* limit on number of queue elements */
69 	uint_t eq_size;			/* number of elements on queue */
70 	uint_t eq_flags;		/* flags for abort and suspend */
71 	id_t eq_sgid;			/* subscription group id for dispq */
72 } fmd_eventq_t;
73 
74 #define	FMD_EVENTQ_ABORT	0x1	/* return NULL from fmd_eventq_delete */
75 #define	FMD_EVENTQ_SUSPEND	0x2	/* suspend in fmd_eventq_delete */
76 
77 extern fmd_eventq_t *fmd_eventq_create(struct fmd_module *,
78     fmd_eventqstat_t *, pthread_mutex_t *, uint_t);
79 extern void fmd_eventq_destroy(fmd_eventq_t *);
80 extern void fmd_eventq_insert_at_head(fmd_eventq_t *, fmd_event_t *);
81 extern void fmd_eventq_insert_at_time(fmd_eventq_t *, fmd_event_t *);
82 extern fmd_event_t *fmd_eventq_delete(fmd_eventq_t *);
83 extern void fmd_eventq_done(fmd_eventq_t *);
84 extern void fmd_eventq_cancel(fmd_eventq_t *, uint_t, void *);
85 extern void fmd_eventq_suspend(fmd_eventq_t *);
86 extern void fmd_eventq_resume(fmd_eventq_t *);
87 extern void fmd_eventq_abort(fmd_eventq_t *);
88 
89 #ifdef	__cplusplus
90 }
91 #endif
92 
93 #endif	/* _FMD_EVENTQ_H */
94