2 #include <bits/libc-lock.h>
6 #include <bits/libc-lock.h>
7 #include <bits/libc-tsd.h>
9 #ifdef _RPC_THREAD_SAFE_
12 /* Variable used in non-threaded applications or for the first thread. */
13 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem
;
14 static struct rpc_thread_variables
*__libc_tsd_RPC_VARS_data
=
15 &__libc_tsd_RPC_VARS_mem
;
18 * Task-variable destructor
21 __rpc_thread_destroy (void)
23 struct rpc_thread_variables
*tvp
= __rpc_thread_variables();
25 if (tvp
!= NULL
&& tvp
!= &__libc_tsd_RPC_VARS_mem
) {
26 __rpc_thread_svc_cleanup ();
27 __rpc_thread_clnt_cleanup ();
28 __rpc_thread_key_cleanup ();
29 free (tvp
->authnone_private_s
);
30 free (tvp
->clnt_perr_buf_s
);
31 free (tvp
->clntraw_private_s
);
32 free (tvp
->svcraw_private_s
);
33 free (tvp
->authdes_cache_s
);
34 free (tvp
->authdes_lru_s
);
41 * Initialize RPC multi-threaded operation
44 rpc_thread_multi (void)
46 __libc_tsd_set (RPC_VARS
, &__libc_tsd_RPC_VARS_mem
);
50 struct rpc_thread_variables
*
51 __rpc_thread_variables (void)
53 __libc_once_define (static, once
);
54 struct rpc_thread_variables
*tvp
;
56 tvp
= __libc_tsd_get (RPC_VARS
);
58 __libc_once (once
, rpc_thread_multi
);
59 tvp
= __libc_tsd_get (RPC_VARS
);
61 tvp
= calloc (1, sizeof *tvp
);
63 __libc_tsd_set (RPC_VARS
, tvp
);
65 tvp
= __libc_tsd_RPC_VARS_data
;
72 /* Global variables If we're single-threaded, or if this is the first
73 thread using the variable, use the existing global variable. This
74 provides backwards compatability for existing applications which
75 dynamically link against this code. */
82 __rpc_thread_svc_fdset (void)
84 struct rpc_thread_variables
*tvp
;
86 tvp
= __rpc_thread_variables ();
87 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
89 return &tvp
->svc_fdset_s
;
92 struct rpc_createerr
*
93 __rpc_thread_createerr (void)
95 struct rpc_thread_variables
*tvp
;
97 tvp
= __rpc_thread_variables ();
98 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
99 return &rpc_createerr
;
100 return &tvp
->rpc_createerr_s
;
104 __rpc_thread_svc_pollfd (void)
106 struct rpc_thread_variables
*tvp
;
108 tvp
= __rpc_thread_variables ();
109 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
111 return &tvp
->svc_pollfd_s
;
115 __rpc_thread_svc_max_pollfd (void)
117 struct rpc_thread_variables
*tvp
;
119 tvp
= __rpc_thread_variables ();
120 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
121 return &svc_max_pollfd
;
122 return &tvp
->svc_max_pollfd_s
;
124 #endif /* _RPC_THREAD_SAFE_ */