1 /* $NetBSD: mt_misc.c,v 1.1 2000/06/02 23:11:11 fvdl Exp $ */ 2 3 /* #pragma ident "@(#)mt_misc.c 1.24 93/04/29 SMI" */ 4 #include <sys/cdefs.h> 5 __FBSDID("$FreeBSD$"); 6 7 #include "namespace.h" 8 #include "reentrant.h" 9 #include <rpc/rpc.h> 10 #include <sys/time.h> 11 #include <stdlib.h> 12 #include <string.h> 13 #include "un-namespace.h" 14 #include "mt_misc.h" 15 16 /* Take these objects out of the application namespace. */ 17 #define svc_lock __svc_lock 18 #define svc_fd_lock __svc_fd_lock 19 #define rpcbaddr_cache_lock __rpcbaddr_cache_lock 20 #define authdes_ops_lock __authdes_ops_lock 21 #define authnone_lock __authnone_lock 22 #define authsvc_lock __authsvc_lock 23 #define clnt_fd_lock __clnt_fd_lock 24 #define clntraw_lock __clntraw_lock 25 #define dupreq_lock __dupreq_lock 26 #define loopnconf_lock __loopnconf_lock 27 #define ops_lock __ops_lock 28 #define proglst_lock __proglst_lock 29 #define rpcsoc_lock __rpcsoc_lock 30 #define svcraw_lock __svcraw_lock 31 #define tsd_lock __tsd_lock 32 #define xprtlist_lock __xprtlist_lock 33 34 /* protects the services list (svc.c) */ 35 pthread_rwlock_t svc_lock = PTHREAD_RWLOCK_INITIALIZER; 36 37 /* protects svc_fdset and the xports[] array */ 38 pthread_rwlock_t svc_fd_lock = PTHREAD_RWLOCK_INITIALIZER; 39 40 /* protects the RPCBIND address cache */ 41 pthread_rwlock_t rpcbaddr_cache_lock = PTHREAD_RWLOCK_INITIALIZER; 42 43 /* serializes authdes ops initializations */ 44 pthread_mutex_t authdes_ops_lock = PTHREAD_MUTEX_INITIALIZER; 45 46 /* protects des stats list */ 47 pthread_mutex_t svcauthdesstats_lock = PTHREAD_MUTEX_INITIALIZER; 48 49 /* auth_none.c serialization */ 50 pthread_mutex_t authnone_lock = PTHREAD_MUTEX_INITIALIZER; 51 52 /* protects the Auths list (svc_auth.c) */ 53 pthread_mutex_t authsvc_lock = PTHREAD_MUTEX_INITIALIZER; 54 55 /* protects client-side fd lock array */ 56 pthread_mutex_t clnt_fd_lock = PTHREAD_MUTEX_INITIALIZER; 57 58 /* clnt_raw.c serialization */ 59 pthread_mutex_t clntraw_lock = PTHREAD_MUTEX_INITIALIZER; 60 61 /* dupreq variables (svc_dg.c) */ 62 pthread_mutex_t dupreq_lock = PTHREAD_MUTEX_INITIALIZER; 63 64 /* loopnconf (rpcb_clnt.c) */ 65 pthread_mutex_t loopnconf_lock = PTHREAD_MUTEX_INITIALIZER; 66 67 /* serializes ops initializations */ 68 pthread_mutex_t ops_lock = PTHREAD_MUTEX_INITIALIZER; 69 70 /* protects proglst list (svc_simple.c) */ 71 pthread_mutex_t proglst_lock = PTHREAD_MUTEX_INITIALIZER; 72 73 /* serializes clnt_com_create() (rpc_soc.c) */ 74 pthread_mutex_t rpcsoc_lock = PTHREAD_MUTEX_INITIALIZER; 75 76 /* svc_raw.c serialization */ 77 pthread_mutex_t svcraw_lock = PTHREAD_MUTEX_INITIALIZER; 78 79 /* protects TSD key creation */ 80 pthread_mutex_t tsd_lock = PTHREAD_MUTEX_INITIALIZER; 81 82 /* xprtlist (svc_generic.c) */ 83 pthread_mutex_t xprtlist_lock = PTHREAD_MUTEX_INITIALIZER; 84 85 #undef rpc_createerr 86 87 struct rpc_createerr rpc_createerr; 88 89 struct rpc_createerr * 90 __rpc_createerr() 91 { 92 static thread_key_t rce_key = 0; 93 struct rpc_createerr *rce_addr = 0; 94 95 if (thr_main()) 96 return (&rpc_createerr); 97 if ((rce_addr = 98 (struct rpc_createerr *)thr_getspecific(rce_key)) != 0) { 99 mutex_lock(&tsd_lock); 100 if (thr_keycreate(&rce_key, free) != 0) { 101 mutex_unlock(&tsd_lock); 102 return (&rpc_createerr); 103 } 104 mutex_unlock(&tsd_lock); 105 } 106 if (!rce_addr) { 107 rce_addr = (struct rpc_createerr *) 108 malloc(sizeof (struct rpc_createerr)); 109 if (thr_setspecific(rce_key, (void *) rce_addr) != 0) { 110 if (rce_addr) 111 free(rce_addr); 112 return (&rpc_createerr); 113 } 114 memset(rce_addr, 0, sizeof (struct rpc_createerr)); 115 return (rce_addr); 116 } 117 return (rce_addr); 118 } 119