OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [rpc_thread.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#define __FORCE_GLIBC
2
#include <features.h>
3
#include <stdio.h>
4
#include <assert.h>
5
#include <bits/libc-tsd.h>
6
#include "rpc_private.h"
7
 
8
#ifdef __UCLIBC_HAS_THREADS__
9
 
10
/* Variable used in non-threaded applications or for the first thread.  */
11
static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
12
static struct rpc_thread_variables *__libc_tsd_RPC_VARS_data =
13
     &__libc_tsd_RPC_VARS_mem;
14
 
15
/*
16
 * Task-variable destructor
17
 */
18
void
19
__rpc_thread_destroy (void)
20
{
21
        struct rpc_thread_variables *tvp = __rpc_thread_variables();
22
 
23
        if (tvp != NULL && tvp != &__libc_tsd_RPC_VARS_mem) {
24
                __rpc_thread_svc_cleanup ();
25
                __rpc_thread_clnt_cleanup ();
26
                //__rpc_thread_key_cleanup ();
27
                free (tvp->authnone_private_s);
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);
33
                free (tvp);
34
        }
35
}
36
 
37
 
38
extern int __pthread_once (pthread_once_t *__once_control,
39
                           void (*__init_routine) (void));
40
 
41
# define __libc_once_define(CLASS, NAME) \
42
  CLASS pthread_once_t NAME = PTHREAD_ONCE_INIT
43
 
44
/* Call handler iff the first call.  */
45
#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
46
  do {                                                                        \
47
    if (__pthread_once != NULL)                                               \
48
      __pthread_once (&(ONCE_CONTROL), (INIT_FUNCTION));                      \
49
    else if ((ONCE_CONTROL) == PTHREAD_ONCE_INIT) {                           \
50
      INIT_FUNCTION ();                                                       \
51
      (ONCE_CONTROL) = !PTHREAD_ONCE_INIT;                                    \
52
    }                                                                         \
53
  } while (0)
54
 
55
/*
56
 * Initialize RPC multi-threaded operation
57
 */
58
static void
59
rpc_thread_multi (void)
60
{
61
  __libc_tsd_set (RPC_VARS, &__libc_tsd_RPC_VARS_mem);
62
}
63
 
64
 
65
struct rpc_thread_variables *
66
__rpc_thread_variables (void)
67
{
68
        __libc_once_define (static, once);
69
        struct rpc_thread_variables *tvp;
70
 
71
        tvp = __libc_tsd_get (RPC_VARS);
72
        if (tvp == NULL) {
73
                __libc_once (once, rpc_thread_multi);
74
                tvp = __libc_tsd_get (RPC_VARS);
75
                if (tvp == NULL) {
76
                        tvp = calloc (1, sizeof *tvp);
77
                        if (tvp != NULL)
78
                                __libc_tsd_set (RPC_VARS, tvp);
79
                        else
80
                                tvp = __libc_tsd_RPC_VARS_data;
81
                }
82
        }
83
        return tvp;
84
}
85
 
86
 
87
/* Global variables If we're single-threaded, or if this is the first
88
   thread using the variable, use the existing global variable.  This
89
   provides backwards compatability for existing applications which
90
   dynamically link against this code.  */
91
#undef svc_fdset
92
#undef rpc_createerr
93
#undef svc_pollfd
94
#undef svc_max_pollfd
95
 
96
fd_set *
97
__rpc_thread_svc_fdset (void)
98
{
99
        struct rpc_thread_variables *tvp;
100
 
101
        tvp = __rpc_thread_variables ();
102
        if (tvp == &__libc_tsd_RPC_VARS_mem)
103
                return &svc_fdset;
104
        return &tvp->svc_fdset_s;
105
}
106
 
107
struct rpc_createerr *
108
__rpc_thread_createerr (void)
109
{
110
        struct rpc_thread_variables *tvp;
111
 
112
        tvp = __rpc_thread_variables ();
113
        if (tvp == &__libc_tsd_RPC_VARS_mem)
114
                return &rpc_createerr;
115
        return &tvp->rpc_createerr_s;
116
}
117
 
118
struct pollfd **
119
__rpc_thread_svc_pollfd (void)
120
{
121
        struct rpc_thread_variables *tvp;
122
 
123
        tvp = __rpc_thread_variables ();
124
        if (tvp == &__libc_tsd_RPC_VARS_mem)
125
                return &svc_pollfd;
126
        return &tvp->svc_pollfd_s;
127
}
128
 
129
int *
130
__rpc_thread_svc_max_pollfd (void)
131
{
132
        struct rpc_thread_variables *tvp;
133
 
134
        tvp = __rpc_thread_variables ();
135
        if (tvp == &__libc_tsd_RPC_VARS_mem)
136
                return &svc_max_pollfd;
137
        return &tvp->svc_max_pollfd_s;
138
}
139
#else
140
 
141
#undef svc_fdset
142
#undef rpc_createerr
143
#undef svc_pollfd
144
#undef svc_max_pollfd
145
 
146
fd_set * __rpc_thread_svc_fdset (void)
147
{
148
    extern fd_set svc_fdset;
149
    return &(svc_fdset);
150
}
151
 
152
struct rpc_createerr * __rpc_thread_createerr (void)
153
{
154
    extern struct rpc_createerr rpc_createerr;
155
    return &(rpc_createerr);
156
}
157
 
158
struct pollfd ** __rpc_thread_svc_pollfd (void)
159
{
160
    extern struct pollfd *svc_pollfd;
161
    return &(svc_pollfd);
162
}
163
 
164
int * __rpc_thread_svc_max_pollfd (void)
165
{
166
    extern int svc_max_pollfd;
167
    return &(svc_max_pollfd);
168
}
169
 
170
#endif /* __UCLIBC_HAS_THREADS__ */
171
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.