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