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