xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_idspace.h (revision 915894ef19890baaed00080f85f6b69e225cda98)
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_IDSPACE_H
28 #define	_FMD_IDSPACE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <pthread.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 typedef struct fmd_idelem {
40 	struct fmd_idelem *ide_next;	/* next element in hash bucket chain */
41 	void *ide_data;			/* data associated with this element */
42 	id_t ide_id;			/* identifier associated w/ element */
43 } fmd_idelem_t;
44 
45 typedef struct fmd_idspace {
46 	char ids_name[32];		/* string name of idspace for debug */
47 	pthread_mutex_t ids_lock;	/* lock protecting idspace contents */
48 	pthread_cond_t ids_cv;		/* condition variable for waiters */
49 	fmd_idelem_t **ids_hash;	/* hash bucket array of fmd_idelems */
50 	uint_t ids_hashlen;		/* size of hash bucket array */
51 	uint_t ids_refs;		/* reference count for idspace_hold */
52 	id_t ids_nextid;		/* next identifier guess for alloc */
53 	id_t ids_minid;			/* minimum identifier value */
54 	id_t ids_maxid;			/* maximum identifier value */
55 	id_t ids_count;			/* number of allocated ids */
56 } fmd_idspace_t;
57 
58 extern fmd_idspace_t *fmd_idspace_create(const char *, id_t, id_t);
59 extern void fmd_idspace_destroy(fmd_idspace_t *);
60 extern void fmd_idspace_apply(fmd_idspace_t *,
61     void (*)(fmd_idspace_t *, id_t, void *), void *);
62 
63 extern void *fmd_idspace_getspecific(fmd_idspace_t *, id_t);
64 extern void fmd_idspace_setspecific(fmd_idspace_t *, id_t, void *);
65 extern int fmd_idspace_contains(fmd_idspace_t *, id_t);
66 extern int fmd_idspace_valid(fmd_idspace_t *, id_t);
67 
68 extern id_t fmd_idspace_xalloc(fmd_idspace_t *, id_t, void *);
69 extern id_t fmd_idspace_alloc(fmd_idspace_t *, void *);
70 extern id_t fmd_idspace_alloc_min(fmd_idspace_t *, void *);
71 extern void *fmd_idspace_free(fmd_idspace_t *, id_t);
72 
73 extern void *fmd_idspace_hold(fmd_idspace_t *, id_t);
74 extern void fmd_idspace_rele(fmd_idspace_t *, id_t);
75 
76 #ifdef	__cplusplus
77 }
78 #endif
79 
80 #endif	/* _FMD_IDSPACE_H */
81