]>
Commit | Line | Data |
---|---|---|
f1e4a4a4 | 1 | #include <stdio.h> |
ec999b8e | 2 | #include <libc-lock.h> |
f1e4a4a4 UD |
3 | #include <rpc/rpc.h> |
4 | #include <assert.h> | |
5 | ||
ec999b8e | 6 | #include <libc-lock.h> |
02d55fe0 | 7 | #include <libc-tsd.h> |
f1e4a4a4 UD |
8 | |
9 | #ifdef _RPC_THREAD_SAFE_ | |
10 | ||
d911bbae | 11 | /* Variable used in non-threaded applications or for the first thread. */ |
f1e4a4a4 | 12 | static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem; |
4e166502 FW |
13 | static __thread struct rpc_thread_variables *thread_rpc_vars |
14 | attribute_tls_model_ie; | |
f1e4a4a4 UD |
15 | |
16 | /* | |
17 | * Task-variable destructor | |
18 | */ | |
e8783fd5 | 19 | void __attribute__ ((section ("__libc_thread_freeres_fn"))) |
f1e4a4a4 UD |
20 | __rpc_thread_destroy (void) |
21 | { | |
4e166502 | 22 | struct rpc_thread_variables *tvp = thread_rpc_vars; |
f1e4a4a4 | 23 | |
ca4fce0e | 24 | if (tvp != NULL) { |
f1e4a4a4 UD |
25 | __rpc_thread_svc_cleanup (); |
26 | __rpc_thread_clnt_cleanup (); | |
27 | __rpc_thread_key_cleanup (); | |
f1e4a4a4 UD |
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); | |
f6bacb8e UD |
33 | free (tvp->svc_xports_s); |
34 | free (tvp->svc_pollfd_s); | |
ca4fce0e UD |
35 | if (tvp != &__libc_tsd_RPC_VARS_mem) |
36 | free (tvp); | |
4e166502 | 37 | thread_rpc_vars = NULL; |
f1e4a4a4 UD |
38 | } |
39 | } | |
2a3d906e | 40 | #ifdef _LIBC_REENTRANT |
e8783fd5 | 41 | text_set_element (__libc_thread_subfreeres, __rpc_thread_destroy); |
2a3d906e RM |
42 | #endif |
43 | text_set_element (__libc_subfreeres, __rpc_thread_destroy); | |
f1e4a4a4 UD |
44 | |
45 | ||
543cf8a9 UD |
46 | /* |
47 | * Initialize RPC multi-threaded operation | |
48 | */ | |
49 | static void | |
50 | rpc_thread_multi (void) | |
51 | { | |
4e166502 | 52 | thread_rpc_vars = &__libc_tsd_RPC_VARS_mem; |
543cf8a9 UD |
53 | } |
54 | ||
55 | ||
f1e4a4a4 UD |
56 | struct rpc_thread_variables * |
57 | __rpc_thread_variables (void) | |
58 | { | |
543cf8a9 | 59 | __libc_once_define (static, once); |
4e166502 | 60 | struct rpc_thread_variables *tvp = thread_rpc_vars; |
f1e4a4a4 | 61 | |
f1e4a4a4 | 62 | if (tvp == NULL) { |
543cf8a9 | 63 | __libc_once (once, rpc_thread_multi); |
4e166502 | 64 | tvp = thread_rpc_vars; |
543cf8a9 UD |
65 | if (tvp == NULL) { |
66 | tvp = calloc (1, sizeof *tvp); | |
67 | if (tvp != NULL) | |
4e166502 | 68 | thread_rpc_vars = tvp; |
543cf8a9 | 69 | } |
f1e4a4a4 UD |
70 | } |
71 | return tvp; | |
72 | } | |
543cf8a9 UD |
73 | |
74 | ||
75 | /* Global variables If we're single-threaded, or if this is the first | |
76 | thread using the variable, use the existing global variable. This | |
382466e0 | 77 | provides backwards compatibility for existing applications which |
543cf8a9 UD |
78 | dynamically link against this code. */ |
79 | #undef svc_fdset | |
80 | #undef rpc_createerr | |
81 | #undef svc_pollfd | |
82 | #undef svc_max_pollfd | |
83 | ||
84 | fd_set * | |
85 | __rpc_thread_svc_fdset (void) | |
86 | { | |
87 | struct rpc_thread_variables *tvp; | |
88 | ||
89 | tvp = __rpc_thread_variables (); | |
d911bbae | 90 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
91 | return &svc_fdset; |
92 | return &tvp->svc_fdset_s; | |
93 | } | |
021db4be | 94 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3) |
543cf8a9 UD |
95 | |
96 | struct rpc_createerr * | |
97 | __rpc_thread_createerr (void) | |
98 | { | |
99 | struct rpc_thread_variables *tvp; | |
100 | ||
101 | tvp = __rpc_thread_variables (); | |
d911bbae | 102 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
103 | return &rpc_createerr; |
104 | return &tvp->rpc_createerr_s; | |
105 | } | |
021db4be | 106 | libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3) |
543cf8a9 UD |
107 | |
108 | struct pollfd ** | |
109 | __rpc_thread_svc_pollfd (void) | |
110 | { | |
111 | struct rpc_thread_variables *tvp; | |
112 | ||
113 | tvp = __rpc_thread_variables (); | |
d911bbae | 114 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
115 | return &svc_pollfd; |
116 | return &tvp->svc_pollfd_s; | |
117 | } | |
7b57bfe5 | 118 | #ifdef EXPORT_RPC_SYMBOLS |
8784cc18 | 119 | libc_hidden_def (__rpc_thread_svc_pollfd) |
7b57bfe5 | 120 | #else |
021db4be | 121 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3) |
7b57bfe5 | 122 | #endif |
543cf8a9 UD |
123 | |
124 | int * | |
125 | __rpc_thread_svc_max_pollfd (void) | |
126 | { | |
127 | struct rpc_thread_variables *tvp; | |
128 | ||
129 | tvp = __rpc_thread_variables (); | |
d911bbae | 130 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
131 | return &svc_max_pollfd; |
132 | return &tvp->svc_max_pollfd_s; | |
133 | } | |
7b57bfe5 | 134 | #ifdef EXPORT_RPC_SYMBOLS |
8784cc18 | 135 | libc_hidden_def (__rpc_thread_svc_max_pollfd) |
7b57bfe5 | 136 | #else |
021db4be | 137 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3) |
7b57bfe5 | 138 | #endif |
8784cc18 | 139 | |
f1e4a4a4 | 140 | #endif /* _RPC_THREAD_SAFE_ */ |