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 xprtlist_lock __xprtlist_lock 32 33 /* protects the services list (svc.c) */ 34 pthread_rwlock_t svc_lock = PTHREAD_RWLOCK_INITIALIZER; 35 36 /* protects svc_fdset and the xports[] array */ 37 pthread_rwlock_t svc_fd_lock = PTHREAD_RWLOCK_INITIALIZER; 38 39 /* protects the RPCBIND address cache */ 40 pthread_rwlock_t rpcbaddr_cache_lock = PTHREAD_RWLOCK_INITIALIZER; 41 42 /* serializes authdes ops initializations */ 43 pthread_mutex_t authdes_ops_lock = PTHREAD_MUTEX_INITIALIZER; 44 45 /* protects des stats list */ 46 pthread_mutex_t svcauthdesstats_lock = PTHREAD_MUTEX_INITIALIZER; 47 48 /* auth_none.c serialization */ 49 pthread_mutex_t authnone_lock = PTHREAD_MUTEX_INITIALIZER; 50 51 /* protects the Auths list (svc_auth.c) */ 52 pthread_mutex_t authsvc_lock = PTHREAD_MUTEX_INITIALIZER; 53 54 /* protects client-side fd lock array */ 55 pthread_mutex_t clnt_fd_lock = PTHREAD_MUTEX_INITIALIZER; 56 57 /* clnt_raw.c serialization */ 58 pthread_mutex_t clntraw_lock = PTHREAD_MUTEX_INITIALIZER; 59 60 /* dupreq variables (svc_dg.c) */ 61 pthread_mutex_t dupreq_lock = PTHREAD_MUTEX_INITIALIZER; 62 63 /* loopnconf (rpcb_clnt.c) */ 64 pthread_mutex_t loopnconf_lock = PTHREAD_MUTEX_INITIALIZER; 65 66 /* serializes ops initializations */ 67 pthread_mutex_t ops_lock = PTHREAD_MUTEX_INITIALIZER; 68 69 /* protects proglst list (svc_simple.c) */ 70 pthread_mutex_t proglst_lock = PTHREAD_MUTEX_INITIALIZER; 71 72 /* serializes clnt_com_create() (rpc_soc.c) */ 73 pthread_mutex_t rpcsoc_lock = PTHREAD_MUTEX_INITIALIZER; 74 75 /* svc_raw.c serialization */ 76 pthread_mutex_t svcraw_lock = PTHREAD_MUTEX_INITIALIZER; 77 78 /* xprtlist (svc_generic.c) */ 79 pthread_mutex_t xprtlist_lock = PTHREAD_MUTEX_INITIALIZER; 80 81 #undef rpc_createerr 82 83 struct rpc_createerr rpc_createerr; 84 static thread_key_t rce_key; 85 static once_t rce_once = ONCE_INITIALIZER; 86 static int rce_key_error; 87 88 static void 89 rce_key_init(void) 90 { 91 92 rce_key_error = thr_keycreate(&rce_key, free); 93 } 94 95 struct rpc_createerr * 96 __rpc_createerr() 97 { 98 struct rpc_createerr *rce_addr = 0; 99 100 if (thr_main()) 101 return (&rpc_createerr); 102 if (thr_once(&rce_once, rce_key_init) != 0 || rce_key_error != 0) 103 return (&rpc_createerr); 104 rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key); 105 if (!rce_addr) { 106 rce_addr = (struct rpc_createerr *) 107 malloc(sizeof (struct rpc_createerr)); 108 if (thr_setspecific(rce_key, (void *) rce_addr) != 0) { 109 if (rce_addr) 110 free(rce_addr); 111 return (&rpc_createerr); 112 } 113 memset(rce_addr, 0, sizeof (struct rpc_createerr)); 114 return (rce_addr); 115 } 116 return (rce_addr); 117 } 118