1/* This file is automatically generated.  DO NOT EDIT! */
2/* Generated from: 	NetBSD: mknative-gcc,v 1.22 2006/06/25 03:06:15 mrg Exp  */
3/* Generated from: NetBSD: mknative.common,v 1.8 2006/05/26 19:17:21 mrg Exp  */
4
5/* Threads compatibility routines for libgcc2 and libobjc.
6   Compile this one with gcc.
7   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
8
9This file is part of GCC.
10
11GCC is free software; you can redistribute it and/or modify it under
12the terms of the GNU General Public License as published by the Free
13Software Foundation; either version 2, or (at your option) any later
14version.
15
16GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17WARRANTY; without even the implied warranty of MERCHANTABILITY or
18FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19for more details.
20
21You should have received a copy of the GNU General Public License
22along with GCC; see the file COPYING.  If not, write to the Free
23Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2402110-1301, USA.  */
25
26/* As a special exception, if you link this library with other files,
27   some of which are compiled with GCC, to produce an executable,
28   this library does not by itself cause the resulting executable
29   to be covered by the GNU General Public License.
30   This exception does not however invalidate any other reasons why
31   the executable file might be covered by the GNU General Public License.  */
32
33
34/* TPF needs its own version of gthr-*.h because TPF always links to
35   the thread library.  However, for performance reasons we still do not
36   want to issue thread api calls unless a check is made to see that we
37   are running as a thread.  */
38
39#ifndef _GLIBCXX_GCC_GTHR_TPF_H
40#define _GLIBCXX_GCC_GTHR_TPF_H
41
42/* POSIX threads specific definitions.
43   Easy, since the interface is just one-to-one mapping.  */
44
45#define __GTHREADS 1
46
47/* Some implementations of <pthread.h> require this to be defined.  */
48#ifndef _REENTRANT
49#define _REENTRANT 1
50#endif
51
52#include <pthread.h>
53#include <unistd.h>
54
55typedef pthread_key_t __gthread_key_t;
56typedef pthread_once_t __gthread_once_t;
57typedef pthread_mutex_t __gthread_mutex_t;
58typedef pthread_mutex_t __gthread_recursive_mutex_t;
59
60#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
61#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
62#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
63#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
64#endif
65
66#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
67#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
68
69#define NOTATHREAD   00
70#define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
71#define ECBPG2PTR  ECBBASEPTR + 0x1000
72#define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16))
73#define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
74
75#if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
76# define __gthrw(name) \
77  extern __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
78# define __gthrw_(name) __gthrw_ ## name
79#else
80# define __gthrw(name)
81# define __gthrw_(name) name
82#endif
83
84__gthrw(pthread_once)
85__gthrw(pthread_key_create)
86__gthrw(pthread_key_delete)
87__gthrw(pthread_getspecific)
88__gthrw(pthread_setspecific)
89__gthrw(pthread_create)
90
91__gthrw(pthread_mutex_lock)
92__gthrw(pthread_mutex_trylock)
93__gthrw(pthread_mutex_unlock)
94
95static inline int
96__gthread_active_p (void)
97{
98  return 1;
99}
100
101static inline int
102__gthread_once (__gthread_once_t *once, void (*func) (void))
103{
104  if (__tpf_pthread_active ())
105    return __gthrw_(pthread_once) (once, func);
106  else
107    return -1;
108}
109
110static inline int
111__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
112{
113  if (__tpf_pthread_active ())
114    return __gthrw_(pthread_key_create) (key, dtor);
115  else
116    return -1;
117}
118
119static inline int
120__gthread_key_delete (__gthread_key_t key)
121{
122  if (__tpf_pthread_active ())
123    return __gthrw_(pthread_key_delete) (key);
124  else
125    return -1;
126}
127
128static inline void *
129__gthread_getspecific (__gthread_key_t key)
130{
131  if (__tpf_pthread_active ())
132    return __gthrw_(pthread_getspecific) (key);
133  else
134    return NULL;
135}
136
137static inline int
138__gthread_setspecific (__gthread_key_t key, const void *ptr)
139{
140  if (__tpf_pthread_active ())
141    return __gthrw_(pthread_setspecific) (key, ptr);
142  else
143    return -1;
144}
145
146static inline int
147__gthread_mutex_lock (__gthread_mutex_t *mutex)
148{
149  if (__tpf_pthread_active ())
150    return __gthrw_(pthread_mutex_lock) (mutex);
151  else
152    return 0;
153}
154
155static inline int
156__gthread_mutex_trylock (__gthread_mutex_t *mutex)
157{
158  if (__tpf_pthread_active ())
159    return __gthrw_(pthread_mutex_trylock) (mutex);
160  else
161    return 0;
162}
163
164static inline int
165__gthread_mutex_unlock (__gthread_mutex_t *mutex)
166{
167  if (__tpf_pthread_active ())
168    return __gthrw_(pthread_mutex_unlock) (mutex);
169  else
170    return 0;
171}
172
173static inline int
174__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
175{
176  if (__tpf_pthread_active ())
177    return __gthread_mutex_lock (mutex);
178  else
179    return 0;
180}
181
182static inline int
183__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
184{
185  if (__tpf_pthread_active ())
186    return __gthread_mutex_trylock (mutex);
187  else
188    return 0;
189}
190
191static inline int
192__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
193{
194  if (__tpf_pthread_active ())
195    return __gthread_mutex_unlock (mutex);
196  else
197    return 0;
198}
199
200#endif /* ! _GLIBCXX_GCC_GTHR_TPF_H */
201