]>
Commit | Line | Data |
---|---|---|
f1e4a4a4 UD |
1 | #include <stdio.h> |
2 | #include <bits/libc-lock.h> | |
3 | #include <rpc/rpc.h> | |
4 | #include <assert.h> | |
5 | ||
6 | #include <bits/libc-lock.h> | |
7 | #include <bits/libc-tsd.h> | |
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; |
4b23f9bd | 13 | __libc_tsd_define (, struct rpc_thread_variables *, RPC_VARS) |
f1e4a4a4 UD |
14 | |
15 | /* | |
16 | * Task-variable destructor | |
17 | */ | |
e8783fd5 | 18 | void __attribute__ ((section ("__libc_thread_freeres_fn"))) |
f1e4a4a4 UD |
19 | __rpc_thread_destroy (void) |
20 | { | |
4b23f9bd JJ |
21 | struct rpc_thread_variables *tvp |
22 | = __libc_tsd_get (struct rpc_thread_variables *, 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); | |
4b23f9bd | 37 | __libc_tsd_set (struct rpc_thread_variables *, 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 | { | |
4b23f9bd JJ |
52 | __libc_tsd_set (struct rpc_thread_variables *, RPC_VARS, |
53 | &__libc_tsd_RPC_VARS_mem); | |
543cf8a9 UD |
54 | } |
55 | ||
56 | ||
f1e4a4a4 UD |
57 | struct rpc_thread_variables * |
58 | __rpc_thread_variables (void) | |
59 | { | |
543cf8a9 | 60 | __libc_once_define (static, once); |
f1e4a4a4 UD |
61 | struct rpc_thread_variables *tvp; |
62 | ||
4b23f9bd | 63 | tvp = __libc_tsd_get (struct rpc_thread_variables *, RPC_VARS); |
f1e4a4a4 | 64 | if (tvp == NULL) { |
543cf8a9 | 65 | __libc_once (once, rpc_thread_multi); |
4b23f9bd | 66 | tvp = __libc_tsd_get (struct rpc_thread_variables *, RPC_VARS); |
543cf8a9 UD |
67 | if (tvp == NULL) { |
68 | tvp = calloc (1, sizeof *tvp); | |
69 | if (tvp != NULL) | |
4b23f9bd JJ |
70 | __libc_tsd_set (struct rpc_thread_variables *, |
71 | RPC_VARS, tvp); | |
543cf8a9 | 72 | else |
4b23f9bd JJ |
73 | tvp = __libc_tsd_get (struct rpc_thread_variables *, |
74 | RPC_VARS); | |
543cf8a9 | 75 | } |
f1e4a4a4 UD |
76 | } |
77 | return tvp; | |
78 | } | |
543cf8a9 UD |
79 | |
80 | ||
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 | |
89 | ||
90 | fd_set * | |
91 | __rpc_thread_svc_fdset (void) | |
92 | { | |
93 | struct rpc_thread_variables *tvp; | |
94 | ||
95 | tvp = __rpc_thread_variables (); | |
d911bbae | 96 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
97 | return &svc_fdset; |
98 | return &tvp->svc_fdset_s; | |
99 | } | |
021db4be | 100 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3) |
543cf8a9 UD |
101 | |
102 | struct rpc_createerr * | |
103 | __rpc_thread_createerr (void) | |
104 | { | |
105 | struct rpc_thread_variables *tvp; | |
106 | ||
107 | tvp = __rpc_thread_variables (); | |
d911bbae | 108 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
109 | return &rpc_createerr; |
110 | return &tvp->rpc_createerr_s; | |
111 | } | |
021db4be | 112 | libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3) |
543cf8a9 UD |
113 | |
114 | struct pollfd ** | |
115 | __rpc_thread_svc_pollfd (void) | |
116 | { | |
117 | struct rpc_thread_variables *tvp; | |
118 | ||
119 | tvp = __rpc_thread_variables (); | |
d911bbae | 120 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
121 | return &svc_pollfd; |
122 | return &tvp->svc_pollfd_s; | |
123 | } | |
7b57bfe5 | 124 | #ifdef EXPORT_RPC_SYMBOLS |
8784cc18 | 125 | libc_hidden_def (__rpc_thread_svc_pollfd) |
7b57bfe5 | 126 | #else |
021db4be | 127 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3) |
7b57bfe5 | 128 | #endif |
543cf8a9 UD |
129 | |
130 | int * | |
131 | __rpc_thread_svc_max_pollfd (void) | |
132 | { | |
133 | struct rpc_thread_variables *tvp; | |
134 | ||
135 | tvp = __rpc_thread_variables (); | |
d911bbae | 136 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
137 | return &svc_max_pollfd; |
138 | return &tvp->svc_max_pollfd_s; | |
139 | } | |
7b57bfe5 | 140 | #ifdef EXPORT_RPC_SYMBOLS |
8784cc18 | 141 | libc_hidden_def (__rpc_thread_svc_max_pollfd) |
7b57bfe5 | 142 | #else |
021db4be | 143 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3) |
7b57bfe5 | 144 | #endif |
8784cc18 | 145 | |
f1e4a4a4 | 146 | #endif /* _RPC_THREAD_SAFE_ */ |