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