Urdu language locale for India.
[glibc.git] / sunrpc / rpc_thread.c
blob796bf086fc32d87af19585cc48a8aac713cac369
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_
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);
24 if (tvp != NULL) {
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)
36 free (tvp);
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);
42 #endif
43 text_set_element (__libc_subfreeres, __rpc_thread_destroy);
47 * Initialize RPC multi-threaded operation
49 static void
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);
64 if (tvp == NULL) {
65 __libc_once (once, rpc_thread_multi);
66 tvp = __libc_tsd_get (struct rpc_thread_variables *, RPC_VARS);
67 if (tvp == NULL) {
68 tvp = calloc (1, sizeof *tvp);
69 if (tvp != NULL)
70 __libc_tsd_set (struct rpc_thread_variables *,
71 RPC_VARS, tvp);
72 else
73 tvp = __libc_tsd_get (struct rpc_thread_variables *,
74 RPC_VARS);
77 return tvp;
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. */
85 #undef svc_fdset
86 #undef rpc_createerr
87 #undef svc_pollfd
88 #undef svc_max_pollfd
90 fd_set *
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)
97 return &svc_fdset;
98 return &tvp->svc_fdset_s;
100 libc_hidden_def (__rpc_thread_svc_fdset)
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_def (__rpc_thread_createerr)
114 struct pollfd **
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)
121 return &svc_pollfd;
122 return &tvp->svc_pollfd_s;
124 libc_hidden_def (__rpc_thread_svc_pollfd)
126 int *
127 __rpc_thread_svc_max_pollfd (void)
129 struct rpc_thread_variables *tvp;
131 tvp = __rpc_thread_variables ();
132 if (tvp == &__libc_tsd_RPC_VARS_mem)
133 return &svc_max_pollfd;
134 return &tvp->svc_max_pollfd_s;
136 libc_hidden_def (__rpc_thread_svc_max_pollfd)
138 #endif /* _RPC_THREAD_SAFE_ */