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 (, struct rpc_thread_variables
*, RPC_VARS
)
16 * Task-variable destructor
18 void __attribute__ ((section ("__libc_thread_freeres_fn")))
19 __rpc_thread_destroy (void)
21 struct rpc_thread_variables
*tvp
22 = __libc_tsd_get (struct rpc_thread_variables
*, RPC_VARS
);
25 __rpc_thread_svc_cleanup ();
26 __rpc_thread_clnt_cleanup ();
27 __rpc_thread_key_cleanup ();
28 free (tvp
->clnt_perr_buf_s
);
29 free (tvp
->clntraw_private_s
);
30 free (tvp
->svcraw_private_s
);
31 free (tvp
->authdes_cache_s
);
32 free (tvp
->authdes_lru_s
);
33 free (tvp
->svc_xports_s
);
34 free (tvp
->svc_pollfd_s
);
35 if (tvp
!= &__libc_tsd_RPC_VARS_mem
)
37 __libc_tsd_set (struct rpc_thread_variables
*, RPC_VARS
, NULL
);
40 #ifdef _LIBC_REENTRANT
41 text_set_element (__libc_thread_subfreeres
, __rpc_thread_destroy
);
43 text_set_element (__libc_subfreeres
, __rpc_thread_destroy
);
47 * Initialize RPC multi-threaded operation
50 rpc_thread_multi (void)
52 __libc_tsd_set (struct rpc_thread_variables
*, RPC_VARS
,
53 &__libc_tsd_RPC_VARS_mem
);
57 struct rpc_thread_variables
*
58 __rpc_thread_variables (void)
60 __libc_once_define (static, once
);
61 struct rpc_thread_variables
*tvp
;
63 tvp
= __libc_tsd_get (struct rpc_thread_variables
*, RPC_VARS
);
65 __libc_once (once
, rpc_thread_multi
);
66 tvp
= __libc_tsd_get (struct rpc_thread_variables
*, RPC_VARS
);
68 tvp
= calloc (1, sizeof *tvp
);
70 __libc_tsd_set (struct rpc_thread_variables
*,
73 tvp
= __libc_tsd_get (struct rpc_thread_variables
*,
81 /* Global variables If we're single-threaded, or if this is the first
82 thread using the variable, use the existing global variable. This
83 provides backwards compatability for existing applications which
84 dynamically link against this code. */
91 __rpc_thread_svc_fdset (void)
93 struct rpc_thread_variables
*tvp
;
95 tvp
= __rpc_thread_variables ();
96 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
98 return &tvp
->svc_fdset_s
;
100 libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset
, GLIBC_2_2_3
)
102 struct rpc_createerr
*
103 __rpc_thread_createerr (void)
105 struct rpc_thread_variables
*tvp
;
107 tvp
= __rpc_thread_variables ();
108 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
109 return &rpc_createerr
;
110 return &tvp
->rpc_createerr_s
;
112 libc_hidden_nolink_sunrpc (__rpc_thread_createerr
, GLIBC_2_2_3
)
115 __rpc_thread_svc_pollfd (void)
117 struct rpc_thread_variables
*tvp
;
119 tvp
= __rpc_thread_variables ();
120 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
122 return &tvp
->svc_pollfd_s
;
124 #ifdef EXPORT_RPC_SYMBOLS
125 libc_hidden_def (__rpc_thread_svc_pollfd
)
127 libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd
, GLIBC_2_2_3
)
131 __rpc_thread_svc_max_pollfd (void)
133 struct rpc_thread_variables
*tvp
;
135 tvp
= __rpc_thread_variables ();
136 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
137 return &svc_max_pollfd
;
138 return &tvp
->svc_max_pollfd_s
;
140 #ifdef EXPORT_RPC_SYMBOLS
141 libc_hidden_def (__rpc_thread_svc_max_pollfd
)
143 libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd
, GLIBC_2_2_3
)
146 #endif /* _RPC_THREAD_SAFE_ */