summary refs log tree commit diff
path: root/sunrpc/rpc_thread.c
blob: 94d9f1fd806963bd188f12ac5461d43a040ee4e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <bits/libc-lock.h>
#include <rpc/rpc.h>
#include <assert.h>

#include <bits/libc-lock.h>
#include <bits/libc-tsd.h>

#ifdef _RPC_THREAD_SAFE_

/* Variable used in non-threaded applications or for the first thread.  */
static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
__libc_tsd_define (, struct rpc_thread_variables *, RPC_VARS)

/*
 * Task-variable destructor
 */
void __attribute__ ((section ("__libc_thread_freeres_fn")))
__rpc_thread_destroy (void)
{
	struct rpc_thread_variables *tvp
	  = __libc_tsd_get (struct rpc_thread_variables *, RPC_VARS);

	if (tvp != NULL) {
		__rpc_thread_svc_cleanup ();
		__rpc_thread_clnt_cleanup ();
		__rpc_thread_key_cleanup ();
		free (tvp->clnt_perr_buf_s);
		free (tvp->clntraw_private_s);
		free (tvp->svcraw_private_s);
		free (tvp->authdes_cache_s);
		free (tvp->authdes_lru_s);
		free (tvp->svc_xports_s);
		free (tvp->svc_pollfd_s);
		if (tvp != &__libc_tsd_RPC_VARS_mem)
			free (tvp);
		__libc_tsd_set (struct rpc_thread_variables *, RPC_VARS, NULL);
	}
}
#ifdef _LIBC_REENTRANT
text_set_element (__libc_thread_subfreeres, __rpc_thread_destroy);
#endif
text_set_element (__libc_subfreeres, __rpc_thread_destroy);


/*
 * Initialize RPC multi-threaded operation
 */
static void
rpc_thread_multi (void)
{
  __libc_tsd_set (struct rpc_thread_variables *, RPC_VARS,
		  &__libc_tsd_RPC_VARS_mem);
}


struct rpc_thread_variables *
__rpc_thread_variables (void)
{
	__libc_once_define (static, once);
	struct rpc_thread_variables *tvp;

	tvp = __libc_tsd_get (struct rpc_thread_variables *, RPC_VARS);
	if (tvp == NULL) {
		__libc_once (once, rpc_thread_multi);
		tvp = __libc_tsd_get (struct rpc_thread_variables *, RPC_VARS);
		if (tvp == NULL) {
			tvp = calloc (1, sizeof *tvp);
			if (tvp != NULL)
				__libc_tsd_set (struct rpc_thread_variables *,
						RPC_VARS, tvp);
			else
				tvp = __libc_tsd_get (struct rpc_thread_variables *,
						      RPC_VARS);
		}
	}
	return tvp;
}


/* Global variables If we're single-threaded, or if this is the first
   thread using the variable, use the existing global variable.  This
   provides backwards compatability for existing applications which
   dynamically link against this code.  */
#undef svc_fdset
#undef rpc_createerr
#undef svc_pollfd
#undef svc_max_pollfd

fd_set *
__rpc_thread_svc_fdset (void)
{
	struct rpc_thread_variables *tvp;

	tvp = __rpc_thread_variables ();
	if (tvp == &__libc_tsd_RPC_VARS_mem)
		return &svc_fdset;
	return &tvp->svc_fdset_s;
}
libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3)

struct rpc_createerr *
__rpc_thread_createerr (void)
{
	struct rpc_thread_variables *tvp;

	tvp = __rpc_thread_variables ();
	if (tvp == &__libc_tsd_RPC_VARS_mem)
		return &rpc_createerr;
	return &tvp->rpc_createerr_s;
}
libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3)

struct pollfd **
__rpc_thread_svc_pollfd (void)
{
	struct rpc_thread_variables *tvp;

	tvp = __rpc_thread_variables ();
	if (tvp == &__libc_tsd_RPC_VARS_mem)
		return &svc_pollfd;
	return &tvp->svc_pollfd_s;
}
#ifdef EXPORT_RPC_SYMBOLS
libc_hidden_def (__rpc_thread_svc_pollfd)
#else
libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3)
#endif

int *
__rpc_thread_svc_max_pollfd (void)
{
	struct rpc_thread_variables *tvp;

	tvp = __rpc_thread_variables ();
	if (tvp == &__libc_tsd_RPC_VARS_mem)
		return &svc_max_pollfd;
	return &tvp->svc_max_pollfd_s;
}
#ifdef EXPORT_RPC_SYMBOLS
libc_hidden_def (__rpc_thread_svc_max_pollfd)
#else
libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3)
#endif

#endif /* _RPC_THREAD_SAFE_ */