2 #include <bits/libc-lock.h>
6 #include <bits/libc-lock.h>
7 #include <bits/libc-tsd.h>
9 #ifdef _RPC_THREAD_SAFE_
11 /* Variable used in non-threaded applications or for the first thread. */
12 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem
;
13 __libc_tsd_define (, RPC_VARS
)
16 * Task-variable destructor
19 __rpc_thread_destroy (void)
21 struct rpc_thread_variables
*tvp
= __libc_tsd_get (RPC_VARS
);
23 if (tvp
!= NULL
&& tvp
!= &__libc_tsd_RPC_VARS_mem
) {
24 __rpc_thread_svc_cleanup ();
25 __rpc_thread_clnt_cleanup ();
26 __rpc_thread_key_cleanup ();
27 free (tvp
->clnt_perr_buf_s
);
28 free (tvp
->clntraw_private_s
);
29 free (tvp
->svcraw_private_s
);
30 free (tvp
->authdes_cache_s
);
31 free (tvp
->authdes_lru_s
);
38 * Initialize RPC multi-threaded operation
41 rpc_thread_multi (void)
43 __libc_tsd_set (RPC_VARS
, &__libc_tsd_RPC_VARS_mem
);
47 struct rpc_thread_variables
*
48 __rpc_thread_variables (void)
50 __libc_once_define (static, once
);
51 struct rpc_thread_variables
*tvp
;
53 tvp
= __libc_tsd_get (RPC_VARS
);
55 __libc_once (once
, rpc_thread_multi
);
56 tvp
= __libc_tsd_get (RPC_VARS
);
58 tvp
= calloc (1, sizeof *tvp
);
60 __libc_tsd_set (RPC_VARS
, tvp
);
62 tvp
= __libc_tsd_get (RPC_VARS
);
69 /* Global variables If we're single-threaded, or if this is the first
70 thread using the variable, use the existing global variable. This
71 provides backwards compatability for existing applications which
72 dynamically link against this code. */
79 __rpc_thread_svc_fdset (void)
81 struct rpc_thread_variables
*tvp
;
83 tvp
= __rpc_thread_variables ();
84 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
86 return &tvp
->svc_fdset_s
;
88 libc_hidden_def (__rpc_thread_svc_fdset
)
90 struct rpc_createerr
*
91 __rpc_thread_createerr (void)
93 struct rpc_thread_variables
*tvp
;
95 tvp
= __rpc_thread_variables ();
96 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
97 return &rpc_createerr
;
98 return &tvp
->rpc_createerr_s
;
100 libc_hidden_def (__rpc_thread_createerr
)
103 __rpc_thread_svc_pollfd (void)
105 struct rpc_thread_variables
*tvp
;
107 tvp
= __rpc_thread_variables ();
108 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
110 return &tvp
->svc_pollfd_s
;
112 libc_hidden_def (__rpc_thread_svc_pollfd
)
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 libc_hidden_def (__rpc_thread_svc_max_pollfd
)
126 #endif /* _RPC_THREAD_SAFE_ */