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