2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
11 #include "rpc_private.h"
14 #ifdef __UCLIBC_HAS_THREADS__
16 #include <bits/libc-tsd.h>
17 #include <bits/libc-lock.h>
19 /* Variable used in non-threaded applications or for the first thread. */
20 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem
;
21 __libc_tsd_define (, RPC_VARS
)
24 * Task-variable destructor
27 __rpc_thread_destroy (void)
29 struct rpc_thread_variables
*tvp
= __libc_tsd_get (RPC_VARS
);
31 if (tvp
!= NULL
&& tvp
!= &__libc_tsd_RPC_VARS_mem
) {
32 __rpc_thread_svc_cleanup ();
33 __rpc_thread_clnt_cleanup ();
34 /*__rpc_thread_key_cleanup (); */
35 free (tvp
->authnone_private_s
);
36 free (tvp
->clnt_perr_buf_s
);
37 free (tvp
->clntraw_private_s
);
38 free (tvp
->svcraw_private_s
);
39 free (tvp
->authdes_cache_s
);
40 free (tvp
->authdes_lru_s
);
42 __libc_tsd_set (RPC_VARS
, NULL
);
47 * Initialize RPC multi-threaded operation
50 rpc_thread_multi (void)
52 __libc_tsd_set (RPC_VARS
, &__libc_tsd_RPC_VARS_mem
);
56 struct rpc_thread_variables attribute_hidden
*
57 __rpc_thread_variables (void)
59 __libc_once_define (static, once
);
60 struct rpc_thread_variables
*tvp
;
62 tvp
= __libc_tsd_get (RPC_VARS
);
64 __libc_once (once
, rpc_thread_multi
);
65 tvp
= __libc_tsd_get (RPC_VARS
);
67 tvp
= calloc (1, sizeof *tvp
);
69 __libc_tsd_set (RPC_VARS
, tvp
);
71 tvp
= __libc_tsd_get (RPC_VARS
);
78 /* Global variables If we're single-threaded, or if this is the first
79 thread using the variable, use the existing global variable. This
80 provides backwards compatability for existing applications which
81 dynamically link against this code. */
88 __rpc_thread_svc_fdset (void)
90 struct rpc_thread_variables
*tvp
;
92 tvp
= __rpc_thread_variables ();
93 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
95 return &tvp
->svc_fdset_s
;
98 struct rpc_createerr
*
99 __rpc_thread_createerr (void)
101 struct rpc_thread_variables
*tvp
;
103 tvp
= __rpc_thread_variables ();
104 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
105 return &rpc_createerr
;
106 return &tvp
->rpc_createerr_s
;
110 __rpc_thread_svc_pollfd (void)
112 struct rpc_thread_variables
*tvp
;
114 tvp
= __rpc_thread_variables ();
115 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
117 return &tvp
->svc_pollfd_s
;
121 __rpc_thread_svc_max_pollfd (void)
123 struct rpc_thread_variables
*tvp
;
125 tvp
= __rpc_thread_variables ();
126 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
127 return &svc_max_pollfd
;
128 return &tvp
->svc_max_pollfd_s
;
135 #undef svc_max_pollfd
137 extern fd_set svc_fdset
;
138 fd_set
* __rpc_thread_svc_fdset (void)
143 extern struct rpc_createerr rpc_createerr
;
144 struct rpc_createerr
* __rpc_thread_createerr (void)
146 return &(rpc_createerr
);
149 extern struct pollfd
*svc_pollfd
;
150 struct pollfd
** __rpc_thread_svc_pollfd (void)
152 return &(svc_pollfd
);
155 extern int svc_max_pollfd
;
156 int * __rpc_thread_svc_max_pollfd (void)
158 return &(svc_max_pollfd
);
161 #endif /* __UCLIBC_HAS_THREADS__ */
163 libc_hidden_def(__rpc_thread_svc_fdset
)
164 libc_hidden_def(__rpc_thread_createerr
)
165 libc_hidden_def(__rpc_thread_svc_pollfd
)
166 libc_hidden_def(__rpc_thread_svc_max_pollfd
)