1 1.1.6.1 nathanw /* $NetBSD: mt_misc.c,v 1.1.6.1 2001/08/08 16:13:44 nathanw Exp $ */ 2 1.1 fvdl 3 1.1 fvdl /* 4 1.1 fvdl * Define and initialize MT data for libnsl. 5 1.1 fvdl * The _libnsl_lock_init() function below is the library's .init handler. 6 1.1 fvdl */ 7 1.1 fvdl 8 1.1 fvdl /* #pragma ident "@(#)mt_misc.c 1.24 93/04/29 SMI" */ 9 1.1 fvdl 10 1.1 fvdl #include "reentrant.h" 11 1.1 fvdl #include <rpc/rpc.h> 12 1.1 fvdl #include <sys/time.h> 13 1.1 fvdl #include <stdlib.h> 14 1.1 fvdl 15 1.1.6.1 nathanw #ifdef _REENTRANT 16 1.1 fvdl 17 1.1.6.1 nathanw /* protects the services list (svc.c) */ 18 1.1.6.1 nathanw rwlock_t svc_lock = RWLOCK_INITIALIZER; 19 1.1.6.1 nathanw /* protects svc_fdset and the xports[] array */ 20 1.1.6.1 nathanw rwlock_t svc_fd_lock = RWLOCK_INITIALIZER; 21 1.1.6.1 nathanw /* protects the RPCBIND address cache */ 22 1.1.6.1 nathanw rwlock_t rpcbaddr_cache_lock = RWLOCK_INITIALIZER; 23 1.1.6.1 nathanw 24 1.1.6.1 nathanw /* protects authdes cache (svcauth_des.c) */ 25 1.1.6.1 nathanw mutex_t authdes_lock = MUTEX_INITIALIZER; 26 1.1.6.1 nathanw /* auth_none.c serialization */ 27 1.1.6.1 nathanw mutex_t authnone_lock = MUTEX_INITIALIZER; 28 1.1.6.1 nathanw /* protects the Auths list (svc_auth.c) */ 29 1.1.6.1 nathanw mutex_t authsvc_lock = MUTEX_INITIALIZER; 30 1.1.6.1 nathanw /* protects client-side fd lock array */ 31 1.1.6.1 nathanw mutex_t clnt_fd_lock = MUTEX_INITIALIZER; 32 1.1.6.1 nathanw /* clnt_raw.c serialization */ 33 1.1.6.1 nathanw mutex_t clntraw_lock = MUTEX_INITIALIZER; 34 1.1.6.1 nathanw /* domainname and domain_fd (getdname.c) and default_domain (rpcdname.c) */ 35 1.1.6.1 nathanw mutex_t dname_lock = MUTEX_INITIALIZER; 36 1.1.6.1 nathanw /* dupreq variables (svc_dg.c) */ 37 1.1.6.1 nathanw mutex_t dupreq_lock = MUTEX_INITIALIZER; 38 1.1.6.1 nathanw /* protects first_time and hostname (key_call.c) */ 39 1.1.6.1 nathanw mutex_t keyserv_lock = MUTEX_INITIALIZER; 40 1.1.6.1 nathanw /* serializes rpc_trace() (rpc_trace.c) */ 41 1.1.6.1 nathanw mutex_t libnsl_trace_lock = MUTEX_INITIALIZER; 42 1.1.6.1 nathanw /* loopnconf (rpcb_clnt.c) */ 43 1.1.6.1 nathanw mutex_t loopnconf_lock = MUTEX_INITIALIZER; 44 1.1.6.1 nathanw /* serializes ops initializations */ 45 1.1.6.1 nathanw mutex_t ops_lock = MUTEX_INITIALIZER; 46 1.1.6.1 nathanw /* protects ``port'' static in bindresvport() */ 47 1.1.6.1 nathanw mutex_t portnum_lock = MUTEX_INITIALIZER; 48 1.1.6.1 nathanw /* protects proglst list (svc_simple.c) */ 49 1.1.6.1 nathanw mutex_t proglst_lock = MUTEX_INITIALIZER; 50 1.1.6.1 nathanw /* serializes clnt_com_create() (rpc_soc.c) */ 51 1.1.6.1 nathanw mutex_t rpcsoc_lock = MUTEX_INITIALIZER; 52 1.1.6.1 nathanw /* svc_raw.c serialization */ 53 1.1.6.1 nathanw mutex_t svcraw_lock = MUTEX_INITIALIZER; 54 1.1.6.1 nathanw /* xprtlist (svc_generic.c) */ 55 1.1.6.1 nathanw mutex_t xprtlist_lock = MUTEX_INITIALIZER; 56 1.1.6.1 nathanw /* serializes calls to public key routines */ 57 1.1.6.1 nathanw mutex_t serialize_pkey = MUTEX_INITIALIZER; 58 1.1 fvdl 59 1.1.6.1 nathanw #endif /* _REENTRANT */ 60 1.1 fvdl 61 1.1 fvdl 62 1.1.6.1 nathanw #undef rpc_createerr 63 1.1 fvdl 64 1.1.6.1 nathanw struct rpc_createerr rpc_createerr; 65 1.1 fvdl 66 1.1.6.1 nathanw #ifdef _REENTRANT 67 1.1.6.1 nathanw static thread_key_t rce_key; 68 1.1.6.1 nathanw static once_t rce_once = ONCE_INITIALIZER; 69 1.1 fvdl 70 1.1.6.1 nathanw static void 71 1.1.6.1 nathanw __rpc_createerr_setup(void) 72 1.1.6.1 nathanw { 73 1.1 fvdl 74 1.1.6.1 nathanw thr_keycreate(&rce_key, free); 75 1.1 fvdl } 76 1.1.6.1 nathanw #endif /* _REENTRANT */ 77 1.1 fvdl 78 1.1.6.1 nathanw struct rpc_createerr* 79 1.1 fvdl __rpc_createerr() 80 1.1 fvdl { 81 1.1.6.1 nathanw #ifdef _REENTRANT 82 1.1 fvdl struct rpc_createerr *rce_addr = 0; 83 1.1.6.1 nathanw extern int __isthreaded; 84 1.1 fvdl 85 1.1.6.1 nathanw if (__isthreaded == 0) 86 1.1 fvdl return (&rpc_createerr); 87 1.1.6.1 nathanw thr_once(&rce_once, __rpc_createerr_setup); 88 1.1.6.1 nathanw rce_addr = thr_getspecific(rce_key); 89 1.1.6.1 nathanw if (rce_addr == NULL) { 90 1.1 fvdl rce_addr = (struct rpc_createerr *) 91 1.1.6.1 nathanw malloc(sizeof (struct rpc_createerr)); 92 1.1.6.1 nathanw thr_setspecific(rce_key, (void *) rce_addr); 93 1.1 fvdl memset(rce_addr, 0, sizeof (struct rpc_createerr)); 94 1.1 fvdl } 95 1.1.6.1 nathanw 96 1.1 fvdl return (rce_addr); 97 1.1 fvdl #else 98 1.1 fvdl return &rpc_createerr; 99 1.1 fvdl #endif 100 1.1 fvdl } 101 1.1.6.1 nathanw 102