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