OSDN Git Service

* de.po: Update.
[pf3gnuchains/gcc-fork.git] / gcc / gthr-tpf.h
1 /* Threads compatibility routines for libgcc2 and libobjc.
2    Compile this one with gcc.
3    Copyright (C) 2004 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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.
11
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.
16
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, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
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.  */
28
29
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.  */
34
35 #ifndef GCC_GTHR_TPF_H
36 #define GCC_GTHR_TPF_H
37
38 /* POSIX threads specific definitions.
39    Easy, since the interface is just one-to-one mapping.  */
40
41 #define __GTHREADS 1
42
43 /* Some implementations of <pthread.h> require this to be defined.  */
44 #ifndef _REENTRANT
45 #define _REENTRANT 1
46 #endif
47
48 #include <pthread.h>
49 #include <unistd.h>
50
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;
55
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
61
62 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
63 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
64
65 #define NOTATHREAD   00
66 #define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
67 #define ECBPG2PTR  ECBBASEPTR + 0x1000
68 #define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 208))
69 #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
70
71 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
72
73 #pragma weak pthread_once
74 #pragma weak pthread_key_create
75 #pragma weak pthread_key_delete
76 #pragma weak pthread_getspecific
77 #pragma weak pthread_setspecific
78 #pragma weak pthread_create
79
80 #pragma weak pthread_mutex_lock
81 #pragma weak pthread_mutex_trylock
82 #pragma weak pthread_mutex_unlock
83
84 #endif /* SUPPORTS_WEAK */
85
86 static inline int
87 __gthread_active_p (void)
88 {
89   return 1;
90 }
91
92 static inline int
93 __gthread_once (__gthread_once_t *once, void (*func) (void))
94 {
95   if (__tpf_pthread_active ())
96     return pthread_once (once, func);
97   else
98     return -1;
99 }
100
101 static inline int
102 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
103 {
104   if (__tpf_pthread_active ())
105     return pthread_key_create (key, dtor);
106   else
107     return -1;
108 }
109
110 static inline int
111 __gthread_key_delete (__gthread_key_t key)
112 {
113   if (__tpf_pthread_active ())
114     return pthread_key_delete (key);
115   else
116     return -1;
117 }
118
119 static inline void *
120 __gthread_getspecific (__gthread_key_t key)
121 {
122   if (__tpf_pthread_active ())
123     return pthread_getspecific (key);
124   else
125     return NULL;
126 }
127
128 static inline int
129 __gthread_setspecific (__gthread_key_t key, const void *ptr)
130 {
131   if (__tpf_pthread_active ())
132     return pthread_setspecific (key, ptr);
133   else
134     return -1;
135 }
136
137 static inline int
138 __gthread_mutex_lock (__gthread_mutex_t *mutex)
139 {
140   if (__tpf_pthread_active ())
141     return pthread_mutex_lock (mutex);
142   else
143     return 0;
144 }
145
146 static inline int
147 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
148 {
149   if (__tpf_pthread_active ())
150     return pthread_mutex_trylock (mutex);
151   else
152     return 0;
153 }
154
155 static inline int
156 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
157 {
158   if (__tpf_pthread_active ())
159     return pthread_mutex_unlock (mutex);
160   else
161     return 0;
162 }
163
164 static inline int
165 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
166 {
167   if (__tpf_pthread_active ())
168     return __gthread_mutex_lock (mutex);
169   else
170     return 0;
171 }
172
173 static inline int
174 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
175 {
176   if (__tpf_pthread_active ())
177     return __gthread_mutex_trylock (mutex);
178   else
179     return 0;
180 }
181
182 static inline int
183 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
184 {
185   if (__tpf_pthread_active ())
186     return __gthread_mutex_unlock (mutex);
187   else
188     return 0;
189 }
190
191 #endif /* ! GCC_GTHR_TPF_H */