1 /*********************************************************************
2 * RPC for the Windows NT Operating System
3 * 1993 by Martin F. Gergeleit
4 * Users may use, copy or modify Sun RPC for the Windows NT Operating
5 * System according to the Sun copyright below.
7 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
8 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
9 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10 *********************************************************************/
12 /* @(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC */
14 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15 * unrestricted use provided that this legend is included on all tape
16 * media and as a part of the software program in whole or part. Users
17 * may copy or modify Sun RPC without charge, but are not authorized
18 * to license or distribute it to anyone else except as part of a product or
19 * program developed by the user.
21 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
25 * Sun RPC is provided with no support and without any obligation on the
26 * part of Sun Microsystems, Inc. to assist in its use, correction,
27 * modification or enhancement.
29 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31 * OR ANY PART THEREOF.
33 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34 * or profits or other special, indirect and consequential damages, even if
35 * Sun has been advised of the possibility of such damages.
37 * Sun Microsystems, Inc.
39 * Mountain View, California 94043
44 * This file should only contain common data (global data) that is exported
45 * by public interfaces
48 /* modified by Scott Cantor to make global data per-thread */
52 pthread_once_t __thr_onc_control = PTHREAD_ONCE_INIT; /* insures single execution */
53 pthread_key_t __thr_key; /* pthread key */
54 void _thr_onc_init(); /* creates pthread key */
55 void _thr_onc_term(void*); /* key destructor function */
58 /* these are only used in an out of memory situation... */
59 static fd_set __g_svc_fdset;
60 static struct opaque_auth __g_null_auth;
61 static struct rpc_createerr_t __g_rpc_createerr_t;
63 /* per-thread global variables encapsulated in one block, makes TLS mgmt easier */
64 struct __thr_rpc_vars {
66 struct opaque_auth __null_auth;
67 struct rpc_createerr_t _rpc_createerr_t;
74 struct __thr_rpc_vars* _get_thr_rpc_vars()
76 struct __thr_rpc_vars* ptr = TlsGetValue(__thr_key);
78 if (!ptr && (ptr=malloc(sizeof(struct __thr_rpc_vars)))) {
79 memset(ptr,0,sizeof(struct __thr_rpc_vars));
80 TlsSetValue(__thr_key, ptr);
83 nt_rpc_report("out of memory");
90 struct __thr_rpc_vars* _get_thr_rpc_vars()
92 struct __thr_rpc_vars* ptr = NULL;
94 pthread_once(&__thr_onc_control, _thr_onc_init);
95 ptr = pthread_getspecific(__thr_key);
96 if (!ptr && (ptr=malloc(sizeof(struct __thr_rpc_vars)))) {
97 memset(ptr,0,sizeof(struct __thr_rpc_vars));
98 pthread_setspecific(__thr_key, ptr);
101 fprintf(stderr,"_get_thr_rpc_vars: out of memory");
108 pthread_key_create(&__thr_key, _thr_onc_term);
111 void _thr_onc_term(void* ptr)
119 #if defined(WIN32) && defined(__BORLANDC__)
120 #define ONC_EXPORT __declspec(dllexport)
125 ONC_EXPORT struct opaque_auth* _thr_null_auth(void)
127 struct __thr_rpc_vars* ptr = _get_thr_rpc_vars();
128 return ptr ? &(ptr->__null_auth) : &__g_null_auth;
131 ONC_EXPORT struct rpc_createerr_t* _thr_rpc_createerr(void)
133 struct __thr_rpc_vars* ptr = _get_thr_rpc_vars();
134 return ptr ? &(ptr->_rpc_createerr_t) : &__g_rpc_createerr_t;
139 ONC_EXPORT fd_set* _thr_svc_fdset(void)
141 struct __thr_rpc_vars* ptr = _get_thr_rpc_vars();
142 return ptr ? &(ptr->_svc_fdset) : &__g_svc_fdset;
149 #endif /* def FD_SETSIZE */