2 #include <bits/libc-lock.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
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
);
45 * Initialize RPC multi-threaded operation
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
);
62 __libc_once (once
, rpc_thread_multi
);
63 tvp
= __libc_tsd_get (RPC_VARS
);
65 tvp
= calloc (1, sizeof *tvp
);
67 __libc_tsd_set (RPC_VARS
, tvp
);
69 tvp
= __libc_tsd_RPC_VARS_data
;
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. */
86 __rpc_thread_svc_fdset (void)
88 struct rpc_thread_variables
*tvp
;
90 tvp
= __rpc_thread_variables ();
91 if (tvp
== &rpc_default
)
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
;
108 __rpc_thread_svc_pollfd (void)
110 struct rpc_thread_variables
*tvp
;
112 tvp
= __rpc_thread_variables ();
113 if (tvp
== &rpc_default
)
115 return &tvp
->svc_pollfd_s
;
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_ */