]>
Commit | Line | Data |
---|---|---|
f1e4a4a4 | 1 | #include <stdio.h> |
f1e4a4a4 UD |
2 | #include <rpc/rpc.h> |
3 | #include <assert.h> | |
4 | ||
ec999b8e | 5 | #include <libc-lock.h> |
02d55fe0 | 6 | #include <libc-tsd.h> |
82f43dd2 | 7 | #include <shlib-compat.h> |
2827ab99 | 8 | #include <libc-symbols.h> |
f1e4a4a4 | 9 | |
f1e4a4a4 | 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 | */ | |
124e0258 | 19 | void |
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 | text_set_element (__libc_subfreeres, __rpc_thread_destroy); |
f1e4a4a4 | 41 | |
543cf8a9 UD |
42 | /* |
43 | * Initialize RPC multi-threaded operation | |
44 | */ | |
45 | static void | |
46 | rpc_thread_multi (void) | |
47 | { | |
4e166502 | 48 | thread_rpc_vars = &__libc_tsd_RPC_VARS_mem; |
543cf8a9 UD |
49 | } |
50 | ||
51 | ||
f1e4a4a4 UD |
52 | struct rpc_thread_variables * |
53 | __rpc_thread_variables (void) | |
54 | { | |
543cf8a9 | 55 | __libc_once_define (static, once); |
4e166502 | 56 | struct rpc_thread_variables *tvp = thread_rpc_vars; |
f1e4a4a4 | 57 | |
f1e4a4a4 | 58 | if (tvp == NULL) { |
543cf8a9 | 59 | __libc_once (once, rpc_thread_multi); |
4e166502 | 60 | tvp = thread_rpc_vars; |
543cf8a9 UD |
61 | if (tvp == NULL) { |
62 | tvp = calloc (1, sizeof *tvp); | |
63 | if (tvp != NULL) | |
4e166502 | 64 | thread_rpc_vars = tvp; |
543cf8a9 | 65 | } |
f1e4a4a4 UD |
66 | } |
67 | return tvp; | |
68 | } | |
543cf8a9 UD |
69 | |
70 | ||
71 | /* Global variables If we're single-threaded, or if this is the first | |
72 | thread using the variable, use the existing global variable. This | |
382466e0 | 73 | provides backwards compatibility for existing applications which |
543cf8a9 UD |
74 | dynamically link against this code. */ |
75 | #undef svc_fdset | |
76 | #undef rpc_createerr | |
77 | #undef svc_pollfd | |
78 | #undef svc_max_pollfd | |
79 | ||
80 | fd_set * | |
81 | __rpc_thread_svc_fdset (void) | |
82 | { | |
83 | struct rpc_thread_variables *tvp; | |
84 | ||
85 | tvp = __rpc_thread_variables (); | |
d911bbae | 86 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
87 | return &svc_fdset; |
88 | return &tvp->svc_fdset_s; | |
89 | } | |
021db4be | 90 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3) |
543cf8a9 UD |
91 | |
92 | struct rpc_createerr * | |
93 | __rpc_thread_createerr (void) | |
94 | { | |
95 | struct rpc_thread_variables *tvp; | |
96 | ||
97 | tvp = __rpc_thread_variables (); | |
d911bbae | 98 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
99 | return &rpc_createerr; |
100 | return &tvp->rpc_createerr_s; | |
101 | } | |
021db4be | 102 | libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3) |
543cf8a9 UD |
103 | |
104 | struct pollfd ** | |
105 | __rpc_thread_svc_pollfd (void) | |
106 | { | |
107 | struct rpc_thread_variables *tvp; | |
108 | ||
109 | tvp = __rpc_thread_variables (); | |
d911bbae | 110 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
111 | return &svc_pollfd; |
112 | return &tvp->svc_pollfd_s; | |
113 | } | |
7b57bfe5 | 114 | #ifdef EXPORT_RPC_SYMBOLS |
8784cc18 | 115 | libc_hidden_def (__rpc_thread_svc_pollfd) |
7b57bfe5 | 116 | #else |
021db4be | 117 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3) |
7b57bfe5 | 118 | #endif |
543cf8a9 UD |
119 | |
120 | int * | |
121 | __rpc_thread_svc_max_pollfd (void) | |
122 | { | |
123 | struct rpc_thread_variables *tvp; | |
124 | ||
125 | tvp = __rpc_thread_variables (); | |
d911bbae | 126 | if (tvp == &__libc_tsd_RPC_VARS_mem) |
543cf8a9 UD |
127 | return &svc_max_pollfd; |
128 | return &tvp->svc_max_pollfd_s; | |
129 | } | |
7b57bfe5 | 130 | #ifdef EXPORT_RPC_SYMBOLS |
8784cc18 | 131 | libc_hidden_def (__rpc_thread_svc_max_pollfd) |
7b57bfe5 | 132 | #else |
021db4be | 133 | libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3) |
7b57bfe5 | 134 | #endif |