xref: /titanic_41/usr/src/cmd/fm/fmd/common/fmd_idspace.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_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 	fmd_idelem_t **ids_hash;	/* hash bucket array of fmd_idelems */
49 	uint_t ids_hashlen;		/* size of hash bucket array */
50 	id_t ids_nextid;		/* next identifier guess for alloc */
51 	id_t ids_minid;			/* minimum identifier value */
52 	id_t ids_maxid;			/* maximum identifier value */
53 	id_t ids_count;			/* number of allocated ids */
54 } fmd_idspace_t;
55 
56 extern fmd_idspace_t *fmd_idspace_create(const char *, id_t, id_t);
57 extern void fmd_idspace_destroy(fmd_idspace_t *);
58 extern void fmd_idspace_apply(fmd_idspace_t *, void (*)(void *, id_t), void *);
59 
60 extern void *fmd_idspace_getspecific(fmd_idspace_t *, id_t);
61 extern void fmd_idspace_setspecific(fmd_idspace_t *, id_t, void *);
62 extern int fmd_idspace_contains(fmd_idspace_t *, id_t);
63 extern int fmd_idspace_valid(fmd_idspace_t *, id_t);
64 
65 extern id_t fmd_idspace_xalloc(fmd_idspace_t *, id_t, void *);
66 extern id_t fmd_idspace_alloc(fmd_idspace_t *, void *);
67 extern void *fmd_idspace_free(fmd_idspace_t *, id_t);
68 
69 #ifdef	__cplusplus
70 }
71 #endif
72 
73 #endif	/* _FMD_IDSPACE_H */
74