* c-common.c (c_sizeof_or_alignof_type): Use fold_convert instead
[official-gcc.git] / gcc / gthr-tpf.h
blobd54a6c801712d67a2288762c05db507c6a1e2da9
1 /* Threads compatibility routines for libgcc2 and libobjc.
2 Compile this one with gcc.
3 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
30 /* TPF needs its own version of gthr-*.h because TPF always links to
31 the thread library. However, for performance reasons we still do not
32 want to issue thread api calls unless a check is made to see that we
33 are running as a thread. */
35 #ifndef GCC_GTHR_TPF_H
36 #define GCC_GTHR_TPF_H
38 /* POSIX threads specific definitions.
39 Easy, since the interface is just one-to-one mapping. */
41 #define __GTHREADS 1
43 /* Some implementations of <pthread.h> require this to be defined. */
44 #ifndef _REENTRANT
45 #define _REENTRANT 1
46 #endif
48 #include <pthread.h>
49 #include <unistd.h>
51 typedef pthread_key_t __gthread_key_t;
52 typedef pthread_once_t __gthread_once_t;
53 typedef pthread_mutex_t __gthread_mutex_t;
54 typedef pthread_mutex_t __gthread_recursive_mutex_t;
56 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
57 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
58 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
59 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
60 #endif
62 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
63 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
65 #define NOTATHREAD 00
66 #define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
67 #define ECBPG2PTR ECBBASEPTR + 0x1000
68 #define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16))
69 #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
71 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
72 # define __gthrw(name) \
73 extern __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)))
74 #else
75 # define __gthrw_asmname(cname) __gthrw_asmnamep (__USER_LABEL_PREFIX__, cname)
76 # define __gthrw_asmnamep(prefix, cname) __gthrw_string (prefix) cname
77 # define __gthrw_string(x) #x
78 # define __gthrw(name) \
79 extern __typeof(name) __gthrw_ ## name __asm (__gthrw_asmname (#name))
80 #endif
82 __gthrw(pthread_once);
83 __gthrw(pthread_key_create);
84 __gthrw(pthread_key_delete);
85 __gthrw(pthread_getspecific);
86 __gthrw(pthread_setspecific);
87 __gthrw(pthread_create);
89 __gthrw(pthread_mutex_lock);
90 __gthrw(pthread_mutex_trylock);
91 __gthrw(pthread_mutex_unlock);
93 static inline int
94 __gthread_active_p (void)
96 return 1;
99 static inline int
100 __gthread_once (__gthread_once_t *once, void (*func) (void))
102 if (__tpf_pthread_active ())
103 return __gthrw_pthread_once (once, func);
104 else
105 return -1;
108 static inline int
109 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
111 if (__tpf_pthread_active ())
112 return __gthrw_pthread_key_create (key, dtor);
113 else
114 return -1;
117 static inline int
118 __gthread_key_delete (__gthread_key_t key)
120 if (__tpf_pthread_active ())
121 return __gthrw_pthread_key_delete (key);
122 else
123 return -1;
126 static inline void *
127 __gthread_getspecific (__gthread_key_t key)
129 if (__tpf_pthread_active ())
130 return __gthrw_pthread_getspecific (key);
131 else
132 return NULL;
135 static inline int
136 __gthread_setspecific (__gthread_key_t key, const void *ptr)
138 if (__tpf_pthread_active ())
139 return __gthrw_pthread_setspecific (key, ptr);
140 else
141 return -1;
144 static inline int
145 __gthread_mutex_lock (__gthread_mutex_t *mutex)
147 if (__tpf_pthread_active ())
148 return __gthrw_pthread_mutex_lock (mutex);
149 else
150 return 0;
153 static inline int
154 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
156 if (__tpf_pthread_active ())
157 return __gthrw_pthread_mutex_trylock (mutex);
158 else
159 return 0;
162 static inline int
163 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
165 if (__tpf_pthread_active ())
166 return __gthrw_pthread_mutex_unlock (mutex);
167 else
168 return 0;
171 static inline int
172 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
174 if (__tpf_pthread_active ())
175 return __gthread_mutex_lock (mutex);
176 else
177 return 0;
180 static inline int
181 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
183 if (__tpf_pthread_active ())
184 return __gthread_mutex_trylock (mutex);
185 else
186 return 0;
189 static inline int
190 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
192 if (__tpf_pthread_active ())
193 return __gthread_mutex_unlock (mutex);
194 else
195 return 0;
198 #endif /* ! GCC_GTHR_TPF_H */