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