* common.opt (flag_gcse_sm): Disable by default.
[official-gcc.git] / gcc / gthr-tpf.h
blob9831c666dc4399fbb65f36964e9c44da74a5722f
1 /* Threads compatibility routines for libgcc2 and libobjc.
2 Compile this one with gcc.
3 Copyright (C) 2004 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, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, 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;
55 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
56 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
58 #define NOTATHREAD 00
59 #define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
60 #define ECBPG2PTR ECBBASEPTR + 0x1000
61 #define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 208))
62 #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
64 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
66 #pragma weak pthread_once
67 #pragma weak pthread_key_create
68 #pragma weak pthread_key_delete
69 #pragma weak pthread_getspecific
70 #pragma weak pthread_setspecific
71 #pragma weak pthread_create
73 #pragma weak pthread_mutex_lock
74 #pragma weak pthread_mutex_trylock
75 #pragma weak pthread_mutex_unlock
77 #endif /* SUPPORTS_WEAK */
79 static inline int
80 __gthread_active_p (void)
82 return 1;
85 static inline int
86 __gthread_once (__gthread_once_t *once, void (*func) (void))
88 if (__tpf_pthread_active ())
89 return pthread_once (once, func);
90 else
91 return -1;
94 static inline int
95 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
97 if (__tpf_pthread_active ())
98 return pthread_key_create (key, dtor);
99 else
100 return -1;
103 static inline int
104 __gthread_key_delete (__gthread_key_t key)
106 if (__tpf_pthread_active ())
107 return pthread_key_delete (key);
108 else
109 return -1;
112 static inline void *
113 __gthread_getspecific (__gthread_key_t key)
115 if (__tpf_pthread_active ())
116 return pthread_getspecific (key);
117 else
118 return NULL;
121 static inline int
122 __gthread_setspecific (__gthread_key_t key, const void *ptr)
124 if (__tpf_pthread_active ())
125 return pthread_setspecific (key, ptr);
126 else
127 return -1;
130 static inline int
131 __gthread_mutex_lock (__gthread_mutex_t *mutex)
133 if (__tpf_pthread_active ())
134 return pthread_mutex_lock (mutex);
135 else
136 return 0;
139 static inline int
140 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
142 if (__tpf_pthread_active ())
143 return pthread_mutex_trylock (mutex);
144 else
145 return 0;
148 static inline int
149 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
151 if (__tpf_pthread_active ())
152 return pthread_mutex_unlock (mutex);
153 else
154 return 0;
157 #endif /* ! GCC_GTHR_TPF_H */