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