xref: /minix3/external/gpl3/gcc/lib/libstdc++-v3/arch/earm/gthr-tpf.h (revision d19d7d58aa5cd1165eefe1a0d807c8afe282db62)
1*d19d7d58SLionel Sambuc /* This file is automatically generated.  DO NOT EDIT! */
2*d19d7d58SLionel Sambuc /* Generated from: 	NetBSD: mknative-gcc,v 1.66 2012/01/10 12:27:54 skrll Exp  */
3*d19d7d58SLionel Sambuc /* Generated from: NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp  */
4*d19d7d58SLionel Sambuc 
5*d19d7d58SLionel Sambuc /* Threads compatibility routines for libgcc2 and libobjc.
6*d19d7d58SLionel Sambuc    Compile this one with gcc.
7*d19d7d58SLionel Sambuc    Copyright (C) 2004, 2005, 2008, 2009 Free Software Foundation, Inc.
8*d19d7d58SLionel Sambuc 
9*d19d7d58SLionel Sambuc This file is part of GCC.
10*d19d7d58SLionel Sambuc 
11*d19d7d58SLionel Sambuc GCC is free software; you can redistribute it and/or modify it under
12*d19d7d58SLionel Sambuc the terms of the GNU General Public License as published by the Free
13*d19d7d58SLionel Sambuc Software Foundation; either version 3, or (at your option) any later
14*d19d7d58SLionel Sambuc version.
15*d19d7d58SLionel Sambuc 
16*d19d7d58SLionel Sambuc GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17*d19d7d58SLionel Sambuc WARRANTY; without even the implied warranty of MERCHANTABILITY or
18*d19d7d58SLionel Sambuc FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19*d19d7d58SLionel Sambuc for more details.
20*d19d7d58SLionel Sambuc 
21*d19d7d58SLionel Sambuc Under Section 7 of GPL version 3, you are granted additional
22*d19d7d58SLionel Sambuc permissions described in the GCC Runtime Library Exception, version
23*d19d7d58SLionel Sambuc 3.1, as published by the Free Software Foundation.
24*d19d7d58SLionel Sambuc 
25*d19d7d58SLionel Sambuc You should have received a copy of the GNU General Public License and
26*d19d7d58SLionel Sambuc a copy of the GCC Runtime Library Exception along with this program;
27*d19d7d58SLionel Sambuc see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
28*d19d7d58SLionel Sambuc <http://www.gnu.org/licenses/>.  */
29*d19d7d58SLionel Sambuc 
30*d19d7d58SLionel Sambuc /* TPF needs its own version of gthr-*.h because TPF always links to
31*d19d7d58SLionel Sambuc    the thread library.  However, for performance reasons we still do not
32*d19d7d58SLionel Sambuc    want to issue thread api calls unless a check is made to see that we
33*d19d7d58SLionel Sambuc    are running as a thread.  */
34*d19d7d58SLionel Sambuc 
35*d19d7d58SLionel Sambuc #ifndef _GLIBCXX_GCC_GTHR_TPF_H
36*d19d7d58SLionel Sambuc #define _GLIBCXX_GCC_GTHR_TPF_H
37*d19d7d58SLionel Sambuc 
38*d19d7d58SLionel Sambuc /* POSIX threads specific definitions.
39*d19d7d58SLionel Sambuc    Easy, since the interface is just one-to-one mapping.  */
40*d19d7d58SLionel Sambuc 
41*d19d7d58SLionel Sambuc #define __GTHREADS 1
42*d19d7d58SLionel Sambuc 
43*d19d7d58SLionel Sambuc /* Some implementations of <pthread.h> require this to be defined.  */
44*d19d7d58SLionel Sambuc #ifndef _REENTRANT
45*d19d7d58SLionel Sambuc #define _REENTRANT 1
46*d19d7d58SLionel Sambuc #endif
47*d19d7d58SLionel Sambuc 
48*d19d7d58SLionel Sambuc #include <pthread.h>
49*d19d7d58SLionel Sambuc #include <unistd.h>
50*d19d7d58SLionel Sambuc 
51*d19d7d58SLionel Sambuc typedef pthread_key_t __gthread_key_t;
52*d19d7d58SLionel Sambuc typedef pthread_once_t __gthread_once_t;
53*d19d7d58SLionel Sambuc typedef pthread_mutex_t __gthread_mutex_t;
54*d19d7d58SLionel Sambuc typedef pthread_mutex_t __gthread_recursive_mutex_t;
55*d19d7d58SLionel Sambuc 
56*d19d7d58SLionel Sambuc #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
57*d19d7d58SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
58*d19d7d58SLionel Sambuc #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
59*d19d7d58SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
60*d19d7d58SLionel Sambuc #endif
61*d19d7d58SLionel Sambuc 
62*d19d7d58SLionel Sambuc #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
63*d19d7d58SLionel Sambuc #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
64*d19d7d58SLionel Sambuc #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
65*d19d7d58SLionel Sambuc 
66*d19d7d58SLionel Sambuc #define NOTATHREAD   00
67*d19d7d58SLionel Sambuc #define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
68*d19d7d58SLionel Sambuc #define ECBPG2PTR  ECBBASEPTR + 0x1000
69*d19d7d58SLionel Sambuc #define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16))
70*d19d7d58SLionel Sambuc #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
71*d19d7d58SLionel Sambuc 
72*d19d7d58SLionel Sambuc #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
73*d19d7d58SLionel Sambuc # define __gthrw(name) \
74*d19d7d58SLionel Sambuc   static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
75*d19d7d58SLionel Sambuc # define __gthrw_(name) __gthrw_ ## name
76*d19d7d58SLionel Sambuc #else
77*d19d7d58SLionel Sambuc # define __gthrw(name)
78*d19d7d58SLionel Sambuc # define __gthrw_(name) name
79*d19d7d58SLionel Sambuc #endif
80*d19d7d58SLionel Sambuc 
81*d19d7d58SLionel Sambuc __gthrw(pthread_once)
__gthrw(pthread_key_create)82*d19d7d58SLionel Sambuc __gthrw(pthread_key_create)
83*d19d7d58SLionel Sambuc __gthrw(pthread_key_delete)
84*d19d7d58SLionel Sambuc __gthrw(pthread_getspecific)
85*d19d7d58SLionel Sambuc __gthrw(pthread_setspecific)
86*d19d7d58SLionel Sambuc __gthrw(pthread_create)
87*d19d7d58SLionel Sambuc 
88*d19d7d58SLionel Sambuc __gthrw(pthread_mutex_lock)
89*d19d7d58SLionel Sambuc __gthrw(pthread_mutex_trylock)
90*d19d7d58SLionel Sambuc __gthrw(pthread_mutex_unlock)
91*d19d7d58SLionel Sambuc __gthrw(pthread_mutexattr_init)
92*d19d7d58SLionel Sambuc __gthrw(pthread_mutexattr_settype)
93*d19d7d58SLionel Sambuc __gthrw(pthread_mutexattr_destroy)
94*d19d7d58SLionel Sambuc __gthrw(pthread_mutex_init)
95*d19d7d58SLionel Sambuc __gthrw(pthread_mutex_destroy)
96*d19d7d58SLionel Sambuc 
97*d19d7d58SLionel Sambuc static inline int
98*d19d7d58SLionel Sambuc __gthread_active_p (void)
99*d19d7d58SLionel Sambuc {
100*d19d7d58SLionel Sambuc   return 1;
101*d19d7d58SLionel Sambuc }
102*d19d7d58SLionel Sambuc 
103*d19d7d58SLionel Sambuc static inline int
__gthread_once(__gthread_once_t * __once,void (* __func)(void))104*d19d7d58SLionel Sambuc __gthread_once (__gthread_once_t *__once, void (*__func) (void))
105*d19d7d58SLionel Sambuc {
106*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
107*d19d7d58SLionel Sambuc     return __gthrw_(pthread_once) (__once, __func);
108*d19d7d58SLionel Sambuc   else
109*d19d7d58SLionel Sambuc     return -1;
110*d19d7d58SLionel Sambuc }
111*d19d7d58SLionel Sambuc 
112*d19d7d58SLionel Sambuc static inline int
__gthread_key_create(__gthread_key_t * __key,void (* __dtor)(void *))113*d19d7d58SLionel Sambuc __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
114*d19d7d58SLionel Sambuc {
115*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
116*d19d7d58SLionel Sambuc     return __gthrw_(pthread_key_create) (__key, __dtor);
117*d19d7d58SLionel Sambuc   else
118*d19d7d58SLionel Sambuc     return -1;
119*d19d7d58SLionel Sambuc }
120*d19d7d58SLionel Sambuc 
121*d19d7d58SLionel Sambuc static inline int
__gthread_key_delete(__gthread_key_t __key)122*d19d7d58SLionel Sambuc __gthread_key_delete (__gthread_key_t __key)
123*d19d7d58SLionel Sambuc {
124*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
125*d19d7d58SLionel Sambuc     return __gthrw_(pthread_key_delete) (__key);
126*d19d7d58SLionel Sambuc   else
127*d19d7d58SLionel Sambuc     return -1;
128*d19d7d58SLionel Sambuc }
129*d19d7d58SLionel Sambuc 
130*d19d7d58SLionel Sambuc static inline void *
__gthread_getspecific(__gthread_key_t __key)131*d19d7d58SLionel Sambuc __gthread_getspecific (__gthread_key_t __key)
132*d19d7d58SLionel Sambuc {
133*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
134*d19d7d58SLionel Sambuc     return __gthrw_(pthread_getspecific) (__key);
135*d19d7d58SLionel Sambuc   else
136*d19d7d58SLionel Sambuc     return NULL;
137*d19d7d58SLionel Sambuc }
138*d19d7d58SLionel Sambuc 
139*d19d7d58SLionel Sambuc static inline int
__gthread_setspecific(__gthread_key_t __key,const void * __ptr)140*d19d7d58SLionel Sambuc __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
141*d19d7d58SLionel Sambuc {
142*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
143*d19d7d58SLionel Sambuc     return __gthrw_(pthread_setspecific) (__key, __ptr);
144*d19d7d58SLionel Sambuc   else
145*d19d7d58SLionel Sambuc     return -1;
146*d19d7d58SLionel Sambuc }
147*d19d7d58SLionel Sambuc 
148*d19d7d58SLionel Sambuc static inline int
__gthread_mutex_destroy(__gthread_mutex_t * __mutex)149*d19d7d58SLionel Sambuc __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
150*d19d7d58SLionel Sambuc {
151*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
152*d19d7d58SLionel Sambuc     return __gthrw_(pthread_mutex_destroy) (__mutex);
153*d19d7d58SLionel Sambuc   else
154*d19d7d58SLionel Sambuc     return 0;
155*d19d7d58SLionel Sambuc }
156*d19d7d58SLionel Sambuc 
157*d19d7d58SLionel Sambuc static inline int
__gthread_mutex_lock(__gthread_mutex_t * __mutex)158*d19d7d58SLionel Sambuc __gthread_mutex_lock (__gthread_mutex_t *__mutex)
159*d19d7d58SLionel Sambuc {
160*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
161*d19d7d58SLionel Sambuc     return __gthrw_(pthread_mutex_lock) (__mutex);
162*d19d7d58SLionel Sambuc   else
163*d19d7d58SLionel Sambuc     return 0;
164*d19d7d58SLionel Sambuc }
165*d19d7d58SLionel Sambuc 
166*d19d7d58SLionel Sambuc static inline int
__gthread_mutex_trylock(__gthread_mutex_t * __mutex)167*d19d7d58SLionel Sambuc __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
168*d19d7d58SLionel Sambuc {
169*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
170*d19d7d58SLionel Sambuc     return __gthrw_(pthread_mutex_trylock) (__mutex);
171*d19d7d58SLionel Sambuc   else
172*d19d7d58SLionel Sambuc     return 0;
173*d19d7d58SLionel Sambuc }
174*d19d7d58SLionel Sambuc 
175*d19d7d58SLionel Sambuc static inline int
__gthread_mutex_unlock(__gthread_mutex_t * __mutex)176*d19d7d58SLionel Sambuc __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
177*d19d7d58SLionel Sambuc {
178*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
179*d19d7d58SLionel Sambuc     return __gthrw_(pthread_mutex_unlock) (__mutex);
180*d19d7d58SLionel Sambuc   else
181*d19d7d58SLionel Sambuc     return 0;
182*d19d7d58SLionel Sambuc }
183*d19d7d58SLionel Sambuc 
184*d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_lock(__gthread_recursive_mutex_t * __mutex)185*d19d7d58SLionel Sambuc __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
186*d19d7d58SLionel Sambuc {
187*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
188*d19d7d58SLionel Sambuc     return __gthread_mutex_lock (__mutex);
189*d19d7d58SLionel Sambuc   else
190*d19d7d58SLionel Sambuc     return 0;
191*d19d7d58SLionel Sambuc }
192*d19d7d58SLionel Sambuc 
193*d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_trylock(__gthread_recursive_mutex_t * __mutex)194*d19d7d58SLionel Sambuc __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
195*d19d7d58SLionel Sambuc {
196*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
197*d19d7d58SLionel Sambuc     return __gthread_mutex_trylock (__mutex);
198*d19d7d58SLionel Sambuc   else
199*d19d7d58SLionel Sambuc     return 0;
200*d19d7d58SLionel Sambuc }
201*d19d7d58SLionel Sambuc 
202*d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_unlock(__gthread_recursive_mutex_t * __mutex)203*d19d7d58SLionel Sambuc __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
204*d19d7d58SLionel Sambuc {
205*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
206*d19d7d58SLionel Sambuc     return __gthread_mutex_unlock (__mutex);
207*d19d7d58SLionel Sambuc   else
208*d19d7d58SLionel Sambuc     return 0;
209*d19d7d58SLionel Sambuc }
210*d19d7d58SLionel Sambuc 
211*d19d7d58SLionel Sambuc static inline int
__gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t * __mutex)212*d19d7d58SLionel Sambuc __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
213*d19d7d58SLionel Sambuc {
214*d19d7d58SLionel Sambuc   if (__tpf_pthread_active ())
215*d19d7d58SLionel Sambuc     {
216*d19d7d58SLionel Sambuc       pthread_mutexattr_t __attr;
217*d19d7d58SLionel Sambuc       int __r;
218*d19d7d58SLionel Sambuc 
219*d19d7d58SLionel Sambuc       __r = __gthrw_(pthread_mutexattr_init) (&__attr);
220*d19d7d58SLionel Sambuc       if (!__r)
221*d19d7d58SLionel Sambuc 	__r = __gthrw_(pthread_mutexattr_settype) (&__attr,
222*d19d7d58SLionel Sambuc 						   PTHREAD_MUTEX_RECURSIVE);
223*d19d7d58SLionel Sambuc       if (!__r)
224*d19d7d58SLionel Sambuc 	__r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
225*d19d7d58SLionel Sambuc       if (!__r)
226*d19d7d58SLionel Sambuc 	__r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
227*d19d7d58SLionel Sambuc       return __r;
228*d19d7d58SLionel Sambuc     }
229*d19d7d58SLionel Sambuc   return 0;
230*d19d7d58SLionel Sambuc }
231*d19d7d58SLionel Sambuc 
232*d19d7d58SLionel Sambuc 
233*d19d7d58SLionel Sambuc #endif /* ! _GLIBCXX_GCC_GTHR_TPF_H */
234