18360efbdSAlfred Perlstein /* $NetBSD: mt_misc.c,v 1.1 2000/06/02 23:11:11 fvdl Exp $ */ 28360efbdSAlfred Perlstein 38360efbdSAlfred Perlstein #include "namespace.h" 49f5afc13SIan Dowse #include "reentrant.h" 58360efbdSAlfred Perlstein #include <rpc/rpc.h> 68360efbdSAlfred Perlstein #include <sys/time.h> 78360efbdSAlfred Perlstein #include <stdlib.h> 8e0554a53SJacques Vidrine #include <string.h> 98360efbdSAlfred Perlstein #include "un-namespace.h" 10235baf26SDaniel Eischen #include "mt_misc.h" 11235baf26SDaniel Eischen 12235baf26SDaniel Eischen /* Take these objects out of the application namespace. */ 13235baf26SDaniel Eischen #define svc_lock __svc_lock 14235baf26SDaniel Eischen #define svc_fd_lock __svc_fd_lock 15235baf26SDaniel Eischen #define rpcbaddr_cache_lock __rpcbaddr_cache_lock 16235baf26SDaniel Eischen #define authdes_ops_lock __authdes_ops_lock 17235baf26SDaniel Eischen #define authnone_lock __authnone_lock 18235baf26SDaniel Eischen #define authsvc_lock __authsvc_lock 19235baf26SDaniel Eischen #define clnt_fd_lock __clnt_fd_lock 20235baf26SDaniel Eischen #define clntraw_lock __clntraw_lock 21235baf26SDaniel Eischen #define dupreq_lock __dupreq_lock 22235baf26SDaniel Eischen #define loopnconf_lock __loopnconf_lock 23235baf26SDaniel Eischen #define ops_lock __ops_lock 24235baf26SDaniel Eischen #define proglst_lock __proglst_lock 25235baf26SDaniel Eischen #define rpcsoc_lock __rpcsoc_lock 26235baf26SDaniel Eischen #define svcraw_lock __svcraw_lock 27235baf26SDaniel Eischen #define xprtlist_lock __xprtlist_lock 288360efbdSAlfred Perlstein 298360efbdSAlfred Perlstein /* protects the services list (svc.c) */ 308360efbdSAlfred Perlstein pthread_rwlock_t svc_lock = PTHREAD_RWLOCK_INITIALIZER; 318360efbdSAlfred Perlstein 328360efbdSAlfred Perlstein /* protects svc_fdset and the xports[] array */ 338360efbdSAlfred Perlstein pthread_rwlock_t svc_fd_lock = PTHREAD_RWLOCK_INITIALIZER; 348360efbdSAlfred Perlstein 358360efbdSAlfred Perlstein /* protects the RPCBIND address cache */ 368360efbdSAlfred Perlstein pthread_rwlock_t rpcbaddr_cache_lock = PTHREAD_RWLOCK_INITIALIZER; 378360efbdSAlfred Perlstein 388360efbdSAlfred Perlstein /* serializes authdes ops initializations */ 398360efbdSAlfred Perlstein pthread_mutex_t authdes_ops_lock = PTHREAD_MUTEX_INITIALIZER; 408360efbdSAlfred Perlstein 418360efbdSAlfred Perlstein /* protects des stats list */ 428360efbdSAlfred Perlstein pthread_mutex_t svcauthdesstats_lock = PTHREAD_MUTEX_INITIALIZER; 438360efbdSAlfred Perlstein 448360efbdSAlfred Perlstein /* auth_none.c serialization */ 458360efbdSAlfred Perlstein pthread_mutex_t authnone_lock = PTHREAD_MUTEX_INITIALIZER; 468360efbdSAlfred Perlstein 478360efbdSAlfred Perlstein /* protects the Auths list (svc_auth.c) */ 488360efbdSAlfred Perlstein pthread_mutex_t authsvc_lock = PTHREAD_MUTEX_INITIALIZER; 498360efbdSAlfred Perlstein 508360efbdSAlfred Perlstein /* protects client-side fd lock array */ 518360efbdSAlfred Perlstein pthread_mutex_t clnt_fd_lock = PTHREAD_MUTEX_INITIALIZER; 528360efbdSAlfred Perlstein 538360efbdSAlfred Perlstein /* clnt_raw.c serialization */ 548360efbdSAlfred Perlstein pthread_mutex_t clntraw_lock = PTHREAD_MUTEX_INITIALIZER; 558360efbdSAlfred Perlstein 568360efbdSAlfred Perlstein /* dupreq variables (svc_dg.c) */ 578360efbdSAlfred Perlstein pthread_mutex_t dupreq_lock = PTHREAD_MUTEX_INITIALIZER; 588360efbdSAlfred Perlstein 598360efbdSAlfred Perlstein /* loopnconf (rpcb_clnt.c) */ 608360efbdSAlfred Perlstein pthread_mutex_t loopnconf_lock = PTHREAD_MUTEX_INITIALIZER; 618360efbdSAlfred Perlstein 628360efbdSAlfred Perlstein /* serializes ops initializations */ 638360efbdSAlfred Perlstein pthread_mutex_t ops_lock = PTHREAD_MUTEX_INITIALIZER; 648360efbdSAlfred Perlstein 658360efbdSAlfred Perlstein /* protects proglst list (svc_simple.c) */ 668360efbdSAlfred Perlstein pthread_mutex_t proglst_lock = PTHREAD_MUTEX_INITIALIZER; 678360efbdSAlfred Perlstein 688360efbdSAlfred Perlstein /* serializes clnt_com_create() (rpc_soc.c) */ 698360efbdSAlfred Perlstein pthread_mutex_t rpcsoc_lock = PTHREAD_MUTEX_INITIALIZER; 708360efbdSAlfred Perlstein 718360efbdSAlfred Perlstein /* svc_raw.c serialization */ 728360efbdSAlfred Perlstein pthread_mutex_t svcraw_lock = PTHREAD_MUTEX_INITIALIZER; 738360efbdSAlfred Perlstein 748360efbdSAlfred Perlstein /* xprtlist (svc_generic.c) */ 758360efbdSAlfred Perlstein pthread_mutex_t xprtlist_lock = PTHREAD_MUTEX_INITIALIZER; 768360efbdSAlfred Perlstein 778360efbdSAlfred Perlstein #undef rpc_createerr 788360efbdSAlfred Perlstein 798360efbdSAlfred Perlstein struct rpc_createerr rpc_createerr; 806f88d2a8SJohn Baldwin static thread_key_t rce_key; 816f88d2a8SJohn Baldwin static once_t rce_once = ONCE_INITIALIZER; 826f88d2a8SJohn Baldwin static int rce_key_error; 836f88d2a8SJohn Baldwin 846f88d2a8SJohn Baldwin static void rce_key_init(void)856f88d2a8SJohn Baldwinrce_key_init(void) 866f88d2a8SJohn Baldwin { 876f88d2a8SJohn Baldwin 886f88d2a8SJohn Baldwin rce_key_error = thr_keycreate(&rce_key, free); 896f88d2a8SJohn Baldwin } 908360efbdSAlfred Perlstein 918360efbdSAlfred Perlstein struct rpc_createerr * __rpc_createerr(void)92587cf682SCraig Rodrigues__rpc_createerr(void) 938360efbdSAlfred Perlstein { 94*513004a2SPedro F. Giffuni struct rpc_createerr *rce_addr = NULL; 958360efbdSAlfred Perlstein 968360efbdSAlfred Perlstein if (thr_main()) 978360efbdSAlfred Perlstein return (&rpc_createerr); 986f88d2a8SJohn Baldwin if (thr_once(&rce_once, rce_key_init) != 0 || rce_key_error != 0) 998360efbdSAlfred Perlstein return (&rpc_createerr); 1006f88d2a8SJohn Baldwin rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key); 1018360efbdSAlfred Perlstein if (!rce_addr) { 1028360efbdSAlfred Perlstein rce_addr = (struct rpc_createerr *) 1038360efbdSAlfred Perlstein malloc(sizeof (struct rpc_createerr)); 1048360efbdSAlfred Perlstein if (thr_setspecific(rce_key, (void *) rce_addr) != 0) { 1058360efbdSAlfred Perlstein free(rce_addr); 1068360efbdSAlfred Perlstein return (&rpc_createerr); 1078360efbdSAlfred Perlstein } 1088360efbdSAlfred Perlstein memset(rce_addr, 0, sizeof (struct rpc_createerr)); 1098360efbdSAlfred Perlstein return (rce_addr); 1108360efbdSAlfred Perlstein } 1118360efbdSAlfred Perlstein return (rce_addr); 1128360efbdSAlfred Perlstein } 113