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