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