expm1 implementation for 128-bit long double.
[glibc.git] / sunrpc / rpc_thread.c
blob1fd1c143ea2f0e09e30cffe0bc9cd2baf7e0a3e7
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. */
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 /* This is the variable used for the first thread. */
19 static struct rpc_thread_variables rpc_default;
22 * Task-variable destructor
24 void
25 __rpc_thread_destroy (void)
27 struct rpc_thread_variables *tvp = __rpc_thread_variables();
29 if (tvp != NULL && tvp != &rpc_default) {
30 __rpc_thread_svc_cleanup ();
31 __rpc_thread_clnt_cleanup ();
32 __rpc_thread_key_cleanup ();
33 free (tvp->authnone_private_s);
34 free (tvp->clnt_perr_buf_s);
35 free (tvp->clntraw_private_s);
36 free (tvp->svcraw_private_s);
37 free (tvp->authdes_cache_s);
38 free (tvp->authdes_lru_s);
39 free (tvp);
45 * Initialize RPC multi-threaded operation
47 static void
48 rpc_thread_multi (void)
50 __libc_tsd_set (RPC_VARS, &rpc_default);
54 struct rpc_thread_variables *
55 __rpc_thread_variables (void)
57 __libc_once_define (static, once);
58 struct rpc_thread_variables *tvp;
60 tvp = __libc_tsd_get (RPC_VARS);
61 if (tvp == NULL) {
62 __libc_once (once, rpc_thread_multi);
63 tvp = __libc_tsd_get (RPC_VARS);
64 if (tvp == NULL) {
65 tvp = calloc (1, sizeof *tvp);
66 if (tvp != NULL)
67 __libc_tsd_set (RPC_VARS, tvp);
68 else
69 tvp = __libc_tsd_RPC_VARS_data;
72 return tvp;
76 /* Global variables If we're single-threaded, or if this is the first
77 thread using the variable, use the existing global variable. This
78 provides backwards compatability for existing applications which
79 dynamically link against this code. */
80 #undef svc_fdset
81 #undef rpc_createerr
82 #undef svc_pollfd
83 #undef svc_max_pollfd
85 fd_set *
86 __rpc_thread_svc_fdset (void)
88 struct rpc_thread_variables *tvp;
90 tvp = __rpc_thread_variables ();
91 if (tvp == &rpc_default)
92 return &svc_fdset;
93 return &tvp->svc_fdset_s;
96 struct rpc_createerr *
97 __rpc_thread_createerr (void)
99 struct rpc_thread_variables *tvp;
101 tvp = __rpc_thread_variables ();
102 if (tvp == &rpc_default)
103 return &rpc_createerr;
104 return &tvp->rpc_createerr_s;
107 struct pollfd **
108 __rpc_thread_svc_pollfd (void)
110 struct rpc_thread_variables *tvp;
112 tvp = __rpc_thread_variables ();
113 if (tvp == &rpc_default)
114 return &svc_pollfd;
115 return &tvp->svc_pollfd_s;
118 int *
119 __rpc_thread_svc_max_pollfd (void)
121 struct rpc_thread_variables *tvp;
123 tvp = __rpc_thread_variables ();
124 if (tvp == &rpc_default)
125 return &svc_max_pollfd;
126 return &tvp->svc_max_pollfd_s;
128 #endif /* _RPC_THREAD_SAFE_ */