xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_idspace.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
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 #include <sys/types.h>
31 #include <pthread.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 typedef struct fmd_idelem {
38 	struct fmd_idelem *ide_next;	/* next element in hash bucket chain */
39 	void *ide_data;			/* data associated with this element */
40 	id_t ide_id;			/* identifier associated w/ element */
41 } fmd_idelem_t;
42 
43 typedef struct fmd_idspace {
44 	char ids_name[32];		/* string name of idspace for debug */
45 	pthread_mutex_t ids_lock;	/* lock protecting idspace contents */
46 	pthread_cond_t ids_cv;		/* condition variable for waiters */
47 	fmd_idelem_t **ids_hash;	/* hash bucket array of fmd_idelems */
48 	uint_t ids_hashlen;		/* size of hash bucket array */
49 	uint_t ids_refs;		/* reference count for idspace_hold */
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 *,
59     void (*)(fmd_idspace_t *, id_t, void *), void *);
60 
61 extern void *fmd_idspace_getspecific(fmd_idspace_t *, id_t);
62 extern void fmd_idspace_setspecific(fmd_idspace_t *, id_t, void *);
63 extern int fmd_idspace_contains(fmd_idspace_t *, id_t);
64 extern int fmd_idspace_valid(fmd_idspace_t *, id_t);
65 
66 extern id_t fmd_idspace_xalloc(fmd_idspace_t *, id_t, void *);
67 extern id_t fmd_idspace_alloc(fmd_idspace_t *, void *);
68 extern id_t fmd_idspace_alloc_min(fmd_idspace_t *, void *);
69 extern void *fmd_idspace_free(fmd_idspace_t *, id_t);
70 
71 extern void *fmd_idspace_hold(fmd_idspace_t *, id_t);
72 extern void fmd_idspace_rele(fmd_idspace_t *, id_t);
73 
74 #ifdef	__cplusplus
75 }
76 #endif
77 
78 #endif	/* _FMD_IDSPACE_H */
79