* iconv/loop.c (put16) [!_STRING_ARCH_unaligned && BIG_ENDIAN]:
[glibc.git] / sunrpc / rpc_thread.c
blobd0dc40b55968fb589a67ecdf42efe76714c9a683
1 #include <stdio.h>
2 #include <bits/libc-lock.h>
3 #include <rpc/rpc.h>
4 #include <assert.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
20 void
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);
35 free (tvp);
41 * Initialize RPC multi-threaded operation
43 static void
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);
57 if (tvp == NULL) {
58 __libc_once (once, rpc_thread_multi);
59 tvp = __libc_tsd_get (RPC_VARS);
60 if (tvp == NULL) {
61 tvp = calloc (1, sizeof *tvp);
62 if (tvp != NULL)
63 __libc_tsd_set (RPC_VARS, tvp);
64 else
65 tvp = __libc_tsd_RPC_VARS_data;
68 return tvp;
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. */
76 #undef svc_fdset
77 #undef rpc_createerr
78 #undef svc_pollfd
79 #undef svc_max_pollfd
81 fd_set *
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)
88 return &svc_fdset;
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;
103 struct pollfd **
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)
110 return &svc_pollfd;
111 return &tvp->svc_pollfd_s;
114 int *
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_ */