xref: /titanic_41/usr/src/lib/libuutil/common/libuutil_impl.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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	_LIBUUTIL_IMPL_H
28 #define	_LIBUUTIL_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <libuutil.h>
33 #include <pthread.h>
34 
35 #include <sys/avl_impl.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 void uu_set_error(uint_t);
42 #pragma rarely_called(uu_set_error)
43 
44 /*PRINTFLIKE1*/
45 void uu_panic(const char *format, ...);
46 #pragma rarely_called(uu_panic)
47 
48 struct uu_dprintf {
49 	char	*uud_name;
50 	uu_dprintf_severity_t uud_severity;
51 	uint_t	uud_flags;
52 };
53 
54 /*
55  * uu_list structures
56  */
57 typedef struct uu_list_node_impl {
58 	struct uu_list_node_impl *uln_next;
59 	struct uu_list_node_impl *uln_prev;
60 } uu_list_node_impl_t;
61 
62 struct uu_list_walk {
63 	uu_list_walk_t	*ulw_next;
64 	uu_list_walk_t	*ulw_prev;
65 
66 	uu_list_t	*ulw_list;
67 	int8_t		ulw_dir;
68 	uint8_t		ulw_robust;
69 	uu_list_node_impl_t *ulw_next_result;
70 };
71 
72 struct uu_list {
73 	uu_list_t	*ul_next;
74 	uu_list_t	*ul_prev;
75 
76 	uu_list_pool_t	*ul_pool;
77 	void		*ul_parent;
78 	size_t		ul_offset;
79 	size_t		ul_numnodes;
80 	uint8_t		ul_debug;
81 	uint8_t		ul_sorted;
82 	uint8_t		ul_index;	/* mark for uu_list_index_ts */
83 
84 	uu_list_node_impl_t ul_null_node;
85 	uu_list_walk_t	ul_null_walk;	/* for robust walkers */
86 };
87 
88 #define	UU_LIST_POOL_MAXNAME	64
89 
90 struct uu_list_pool {
91 	uu_list_pool_t	*ulp_next;
92 	uu_list_pool_t	*ulp_prev;
93 
94 	char		ulp_name[UU_LIST_POOL_MAXNAME];
95 	size_t		ulp_nodeoffset;
96 	size_t		ulp_objsize;
97 	uu_compare_fn_t	*ulp_cmp;
98 	uint8_t		ulp_debug;
99 	uint8_t		ulp_last_index;
100 	pthread_mutex_t	ulp_lock;		/* protects null_list */
101 	uu_list_t	ulp_null_list;
102 };
103 
104 /*
105  * uu_avl structures
106  */
107 typedef struct avl_node		uu_avl_node_impl_t;
108 
109 struct uu_avl_walk {
110 	uu_avl_walk_t	*uaw_next;
111 	uu_avl_walk_t	*uaw_prev;
112 
113 	uu_avl_t	*uaw_avl;
114 	void		*uaw_next_result;
115 	int8_t		uaw_dir;
116 	uint8_t		uaw_robust;
117 };
118 
119 struct uu_avl {
120 	uu_avl_t	*ua_next;
121 	uu_avl_t	*ua_prev;
122 
123 	uu_avl_pool_t	*ua_pool;
124 	void		*ua_parent;
125 	uint8_t		ua_debug;
126 	uint8_t		ua_index;	/* mark for uu_avl_index_ts */
127 
128 	struct avl_tree	ua_tree;
129 	uu_avl_walk_t	ua_null_walk;
130 };
131 
132 #define	UU_AVL_POOL_MAXNAME	64
133 
134 struct uu_avl_pool {
135 	uu_avl_pool_t	*uap_next;
136 	uu_avl_pool_t	*uap_prev;
137 
138 	char		uap_name[UU_AVL_POOL_MAXNAME];
139 	size_t		uap_nodeoffset;
140 	size_t		uap_objsize;
141 	uu_compare_fn_t	*uap_cmp;
142 	uint8_t		uap_debug;
143 	uint8_t		uap_last_index;
144 	pthread_mutex_t	uap_lock;		/* protects null_avl */
145 	uu_avl_t	uap_null_avl;
146 };
147 
148 /*
149  * atfork() handlers
150  */
151 void uu_avl_lockup(void);
152 void uu_avl_release(void);
153 
154 void uu_list_lockup(void);
155 void uu_list_release(void);
156 
157 #ifdef	__cplusplus
158 }
159 #endif
160 
161 #endif	/* _LIBUUTIL_IMPL_H */
162