xref: /titanic_50/usr/src/lib/libnisdb/nis_hashitem.h (revision 080575042aba2197b425ebfd52061dea061a9aa1)
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	_NIS_HASHITEM_H
28 #define	_NIS_HASHITEM_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <pthread.h>
33 #include <rpcsvc/nis.h>
34 
35 #include "nisdb_rw.h"
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /* Private versions of the various NIS_HASH_ITEM functions */
42 typedef struct __nis_item_item {
43 	pthread_cond_t		lock;
44 	nis_name		name;
45 	int			keychain;
46 	uint32_t		readers;
47 	pthread_t		last_reader_id;
48 	uint32_t		writer;
49 	pthread_t		writer_id;
50 	struct __nis_item_item	*next;
51 	struct __nis_item_item	*prv_item;
52 	struct __nis_item_item	*nxt_item;
53 } __nis_hash_item_mt;
54 
55 typedef struct {
56 	pthread_mutex_t		lock;
57 	pthread_cond_t		cond;
58 	pthread_mutex_t		traverser_id_lock;
59 							/*
60 							 * Protects 'traversed'
61 							 * and 'traverser_id'.
62 							 */
63 	uint32_t		traversed;
64 	pthread_t		traverser_id;
65 	uint32_t		locked_items;
66 	__nis_hash_item_mt	*keys[64];
67 	__nis_hash_item_mt	*first;
68 	void			(*destroyItem)(void *);
69 } __nis_hash_table_mt;
70 
71 #define	NIS_HASH_TABLE_MT_INIT	{ \
72 					PTHREAD_MUTEX_INITIALIZER, \
73 					{0}, \
74 					PTHREAD_MUTEX_INITIALIZER \
75 					/* Zero is fine for the rest */ \
76 				}
77 
78 #define	LOCK_LIST(list, msg)	(void) __nis_lock_hash_table(list, 1, msg)
79 #define	ULOCK_LIST(list, msg)	(void) __nis_ulock_hash_table(list, 1, msg)
80 
81 
82 extern void	__nis_init_hash_table(__nis_hash_table_mt *, void (*)(void *));
83 extern int	__nis_lock_hash_table(__nis_hash_table_mt *, int, char *);
84 extern int	__nis_ulock_hash_table(__nis_hash_table_mt *, int, char *);
85 extern int	__nis_insert_item_mt(void *, __nis_hash_table_mt *, int);
86 extern void	__nis_insert_name_mt(nis_name, __nis_hash_table_mt *);
87 extern void	*__nis_find_item_mt(nis_name, __nis_hash_table_mt *, int,
88 					int *);
89 extern void	*__nis_pop_item_mt(__nis_hash_table_mt *);
90 extern void	*__nis_remove_item_mt(nis_name, __nis_hash_table_mt *);
91 extern int	__nis_release_item(void *, __nis_hash_table_mt *, int);
92 extern int	__nis_item_access(void *);
93 extern void	__nis_scan_table_mt(__nis_hash_table_mt *,
94 			bool_t (*)(__nis_hash_item_mt *, void *), void *);
95 
96 /* Define-magic */
97 #define	NIS_HASH_ITEM			__nis_hash_item_mt
98 #define	NIS_HASH_TABLE			__nis_hash_table_mt
99 #define	nis_insert_item(i, t)		__nis_insert_item_mt(i, t, -1)
100 #define	nis_insert_item_rw(i, t, rw)	__nis_insert_item_mt(i, t, rw)
101 #define	nis_insert_name(n, t)		__nis_insert_name_mt(n, t)
102 #define	nis_find_item(i, t)		__nis_find_item_mt(i, t, -1, 0)
103 #define	nis_find_item_rw(i, t, rw)	__nis_find_item_mt(i, t, rw, 0)
104 #define	nis_pop_item			__nis_pop_item_mt
105 #define	nis_remove_item			__nis_remove_item_mt
106 #define	nis_scan_table			__nis_scan_table_mt
107 
108 #define	MT_LOCK_TYPE(type)		(type < 0)?"W":(type > 0)?"R":"N"
109 
110 #ifdef	NIS_MT_DEBUG
111 #define	MT_LOG(condition, syslogarg)	if (condition) syslog ## syslogarg
112 #else
113 #define	MT_LOG(condition, syslogarg)
114 #endif	/* NIS_MT_DEBUG */
115 
116 #ifdef	__cplusplus
117 }
118 #endif	/* __cplusplus */
119 
120 #endif	/* _NIS_HASHITEM_H */
121