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 /* Variable used in non-threaded applications or for the first thread. */
17 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem
;
18 __libc_tsd_define (, RPC_VARS
)
21 * Task-variable destructor
24 __rpc_thread_destroy (void)
26 struct rpc_thread_variables
*tvp
= __libc_tsd_get (RPC_VARS
);
28 if (tvp
!= NULL
&& tvp
!= &__libc_tsd_RPC_VARS_mem
) {
29 __rpc_thread_svc_cleanup ();
30 __rpc_thread_clnt_cleanup ();
31 /*__rpc_thread_key_cleanup (); */
32 free (tvp
->authnone_private_s
);
33 free (tvp
->clnt_perr_buf_s
);
34 free (tvp
->clntraw_private_s
);
35 free (tvp
->svcraw_private_s
);
36 free (tvp
->authdes_cache_s
);
37 free (tvp
->authdes_lru_s
);
39 __libc_tsd_set (RPC_VARS
, NULL
);
44 * Initialize RPC multi-threaded operation
47 rpc_thread_multi (void)
49 __libc_tsd_set (RPC_VARS
, &__libc_tsd_RPC_VARS_mem
);
52 __UCLIBC_MUTEX_STATIC(mylock
, PTHREAD_MUTEX_INITIALIZER
);
54 struct rpc_thread_variables attribute_hidden
*
55 __rpc_thread_variables (void)
57 struct rpc_thread_variables
*tvp
;
59 __UCLIBC_MUTEX_LOCK(mylock
);
60 tvp
= __libc_tsd_get (RPC_VARS
);
63 tvp
= __libc_tsd_get (RPC_VARS
);
65 tvp
= calloc (1, sizeof *tvp
);
67 __libc_tsd_set (RPC_VARS
, tvp
);
69 tvp
= __libc_tsd_get (RPC_VARS
);
72 __UCLIBC_MUTEX_UNLOCK(mylock
);
77 /* Global variables If we're single-threaded, or if this is the first
78 thread using the variable, use the existing global variable. This
79 provides backwards compatability for existing applications which
80 dynamically link against this code. */
87 __rpc_thread_svc_fdset (void)
89 struct rpc_thread_variables
*tvp
;
91 tvp
= __rpc_thread_variables ();
92 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
94 return &tvp
->svc_fdset_s
;
97 struct rpc_createerr
*
98 __rpc_thread_createerr (void)
100 struct rpc_thread_variables
*tvp
;
102 tvp
= __rpc_thread_variables ();
103 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
104 return &rpc_createerr
;
105 return &tvp
->rpc_createerr_s
;
109 __rpc_thread_svc_pollfd (void)
111 struct rpc_thread_variables
*tvp
;
113 tvp
= __rpc_thread_variables ();
114 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
116 return &tvp
->svc_pollfd_s
;
120 __rpc_thread_svc_max_pollfd (void)
122 struct rpc_thread_variables
*tvp
;
124 tvp
= __rpc_thread_variables ();
125 if (tvp
== &__libc_tsd_RPC_VARS_mem
)
126 return &svc_max_pollfd
;
127 return &tvp
->svc_max_pollfd_s
;
134 #undef svc_max_pollfd
136 extern fd_set svc_fdset
;
137 fd_set
* __rpc_thread_svc_fdset (void)
142 extern struct rpc_createerr rpc_createerr
;
143 struct rpc_createerr
* __rpc_thread_createerr (void)
145 return &(rpc_createerr
);
148 extern struct pollfd
*svc_pollfd
;
149 struct pollfd
** __rpc_thread_svc_pollfd (void)
151 return &(svc_pollfd
);
154 extern int svc_max_pollfd
;
155 int * __rpc_thread_svc_max_pollfd (void)
157 return &(svc_max_pollfd
);
160 #endif /* __UCLIBC_HAS_THREADS__ */
162 libc_hidden_def(__rpc_thread_svc_fdset
)
163 libc_hidden_def(__rpc_thread_createerr
)
164 libc_hidden_def(__rpc_thread_svc_pollfd
)
165 libc_hidden_def(__rpc_thread_svc_max_pollfd
)