1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _NIS_HASHITEM_H 28*7c478bd9Sstevel@tonic-gate #define _NIS_HASHITEM_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #include <pthread.h> 31*7c478bd9Sstevel@tonic-gate #include <rpcsvc/nis.h> 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "nisdb_rw.h" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 36*7c478bd9Sstevel@tonic-gate extern "C" { 37*7c478bd9Sstevel@tonic-gate #endif 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* Private versions of the various NIS_HASH_ITEM functions */ 40*7c478bd9Sstevel@tonic-gate typedef struct __nis_item_item { 41*7c478bd9Sstevel@tonic-gate pthread_cond_t lock; 42*7c478bd9Sstevel@tonic-gate nis_name name; 43*7c478bd9Sstevel@tonic-gate int keychain; 44*7c478bd9Sstevel@tonic-gate uint32_t readers; 45*7c478bd9Sstevel@tonic-gate pthread_t last_reader_id; 46*7c478bd9Sstevel@tonic-gate uint32_t writer; 47*7c478bd9Sstevel@tonic-gate pthread_t writer_id; 48*7c478bd9Sstevel@tonic-gate struct __nis_item_item *next; 49*7c478bd9Sstevel@tonic-gate struct __nis_item_item *prv_item; 50*7c478bd9Sstevel@tonic-gate struct __nis_item_item *nxt_item; 51*7c478bd9Sstevel@tonic-gate } __nis_hash_item_mt; 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate typedef struct { 54*7c478bd9Sstevel@tonic-gate pthread_mutex_t lock; 55*7c478bd9Sstevel@tonic-gate pthread_cond_t cond; 56*7c478bd9Sstevel@tonic-gate pthread_mutex_t traverser_id_lock; 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * Protects 'traversed' 59*7c478bd9Sstevel@tonic-gate * and 'traverser_id'. 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate uint32_t traversed; 62*7c478bd9Sstevel@tonic-gate pthread_t traverser_id; 63*7c478bd9Sstevel@tonic-gate uint32_t locked_items; 64*7c478bd9Sstevel@tonic-gate __nis_hash_item_mt *keys[64]; 65*7c478bd9Sstevel@tonic-gate __nis_hash_item_mt *first; 66*7c478bd9Sstevel@tonic-gate void (*destroyItem)(void *); 67*7c478bd9Sstevel@tonic-gate } __nis_hash_table_mt; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate #define NIS_HASH_TABLE_MT_INIT { \ 70*7c478bd9Sstevel@tonic-gate PTHREAD_MUTEX_INITIALIZER, \ 71*7c478bd9Sstevel@tonic-gate {0}, \ 72*7c478bd9Sstevel@tonic-gate PTHREAD_MUTEX_INITIALIZER \ 73*7c478bd9Sstevel@tonic-gate /* Zero is fine for the rest */ \ 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate #define LOCK_LIST(list, msg) (void) __nis_lock_hash_table(list, 1, msg) 77*7c478bd9Sstevel@tonic-gate #define ULOCK_LIST(list, msg) (void) __nis_ulock_hash_table(list, 1, msg) 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate extern void __nis_init_hash_table(__nis_hash_table_mt *, void (*)(void *)); 81*7c478bd9Sstevel@tonic-gate extern int __nis_lock_hash_table(__nis_hash_table_mt *, int, char *); 82*7c478bd9Sstevel@tonic-gate extern int __nis_ulock_hash_table(__nis_hash_table_mt *, int, char *); 83*7c478bd9Sstevel@tonic-gate extern int __nis_insert_item_mt(void *, __nis_hash_table_mt *, int); 84*7c478bd9Sstevel@tonic-gate extern void __nis_insert_name_mt(nis_name, __nis_hash_table_mt *); 85*7c478bd9Sstevel@tonic-gate extern void *__nis_find_item_mt(nis_name, __nis_hash_table_mt *, int, 86*7c478bd9Sstevel@tonic-gate int *); 87*7c478bd9Sstevel@tonic-gate extern void *__nis_pop_item_mt(__nis_hash_table_mt *); 88*7c478bd9Sstevel@tonic-gate extern void *__nis_remove_item_mt(nis_name, __nis_hash_table_mt *); 89*7c478bd9Sstevel@tonic-gate extern int __nis_release_item(void *, __nis_hash_table_mt *, int); 90*7c478bd9Sstevel@tonic-gate extern int __nis_item_access(void *); 91*7c478bd9Sstevel@tonic-gate extern void __nis_scan_table_mt(__nis_hash_table_mt *, 92*7c478bd9Sstevel@tonic-gate bool_t (*)(__nis_hash_item_mt *, void *), void *); 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* Define-magic */ 95*7c478bd9Sstevel@tonic-gate #define NIS_HASH_ITEM __nis_hash_item_mt 96*7c478bd9Sstevel@tonic-gate #define NIS_HASH_TABLE __nis_hash_table_mt 97*7c478bd9Sstevel@tonic-gate #define nis_insert_item(i, t) __nis_insert_item_mt(i, t, -1) 98*7c478bd9Sstevel@tonic-gate #define nis_insert_item_rw(i, t, rw) __nis_insert_item_mt(i, t, rw) 99*7c478bd9Sstevel@tonic-gate #define nis_insert_name(n, t) __nis_insert_name_mt(n, t) 100*7c478bd9Sstevel@tonic-gate #define nis_find_item(i, t) __nis_find_item_mt(i, t, -1, 0) 101*7c478bd9Sstevel@tonic-gate #define nis_find_item_rw(i, t, rw) __nis_find_item_mt(i, t, rw, 0) 102*7c478bd9Sstevel@tonic-gate #define nis_pop_item __nis_pop_item_mt 103*7c478bd9Sstevel@tonic-gate #define nis_remove_item __nis_remove_item_mt 104*7c478bd9Sstevel@tonic-gate #define nis_scan_table __nis_scan_table_mt 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #define MT_LOCK_TYPE(type) (type < 0)?"W":(type > 0)?"R":"N" 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate #ifdef NIS_MT_DEBUG 109*7c478bd9Sstevel@tonic-gate #define MT_LOG(condition, syslogarg) if (condition) syslog ## syslogarg 110*7c478bd9Sstevel@tonic-gate #else 111*7c478bd9Sstevel@tonic-gate #define MT_LOG(condition, syslogarg) 112*7c478bd9Sstevel@tonic-gate #endif /* NIS_MT_DEBUG */ 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate #endif /* __cplusplus */ 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate #endif /* _NIS_HASHITEM_H */ 119