1227825Stheraven/* This file is automatically generated.  DO NOT EDIT! */
2227825Stheraven/* Generated from: 	NetBSD: mknative-gcc,v 1.18 2006/05/23 10:55:55 mrg Exp  */
3227825Stheraven/* Generated from: NetBSD: mknative.common,v 1.7 2006/05/17 03:27:19 mrg Exp  */
4227825Stheraven
5227825Stheraven/* Threads compatibility routines for libgcc2 and libobjc.
6227825Stheraven   Compile this one with gcc.
7227825Stheraven   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
8227825Stheraven
9227825StheravenThis file is part of GCC.
10262801Sdim
11262801SdimGCC is free software; you can redistribute it and/or modify it under
12262801Sdimthe terms of the GNU General Public License as published by the Free
13262801SdimSoftware Foundation; either version 2, or (at your option) any later
14278724Sdimversion.
15262801Sdim
16227825StheravenGCC is distributed in the hope that it will be useful, but WITHOUT ANY
17227825StheravenWARRANTY; without even the implied warranty of MERCHANTABILITY or
18227825StheravenFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19278724Sdimfor more details.
20232950Stheraven
21278724SdimYou should have received a copy of the GNU General Public License
22262801Sdimalong with GCC; see the file COPYING.  If not, write to the Free
23227825StheravenSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24227825Stheraven02110-1301, USA.  */
25278724Sdim
26227825Stheraven/* As a special exception, if you link this library with other files,
27278724Sdim   some of which are compiled with GCC, to produce an executable,
28278724Sdim   this library does not by itself cause the resulting executable
29278724Sdim   to be covered by the GNU General Public License.
30227825Stheraven   This exception does not however invalidate any other reasons why
31227825Stheraven   the executable file might be covered by the GNU General Public License.  */
32227825Stheraven
33262801Sdim
34278724Sdim/* TPF needs its own version of gthr-*.h because TPF always links to
35262801Sdim   the thread library.  However, for performance reasons we still do not
36262801Sdim   want to issue thread api calls unless a check is made to see that we
37262801Sdim   are running as a thread.  */
38262801Sdim
39262801Sdim#ifndef _GLIBCXX_GCC_GTHR_TPF_H
40262801Sdim#define _GLIBCXX_GCC_GTHR_TPF_H
41262801Sdim
42262801Sdim/* POSIX threads specific definitions.
43262801Sdim   Easy, since the interface is just one-to-one mapping.  */
44262801Sdim
45262801Sdim#define __GTHREADS 1
46262801Sdim
47262801Sdim/* Some implementations of <pthread.h> require this to be defined.  */
48262801Sdim#ifndef _REENTRANT
49262801Sdim#define _REENTRANT 1
50262801Sdim#endif
51262801Sdim
52278724Sdim#include <pthread.h>
53278724Sdim#include <unistd.h>
54278724Sdim
55227825Stheraventypedef pthread_key_t __gthread_key_t;
56278724Sdimtypedef pthread_once_t __gthread_once_t;
57278724Sdimtypedef pthread_mutex_t __gthread_mutex_t;
58278724Sdimtypedef pthread_mutex_t __gthread_recursive_mutex_t;
59278724Sdim
60278724Sdim#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
61278724Sdim#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
62278724Sdim#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
63278724Sdim#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
64278724Sdim#endif
65278724Sdim
66278724Sdim#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
67278724Sdim#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
68278724Sdim
69278724Sdim#define NOTATHREAD   00
70278724Sdim#define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
71278724Sdim#define ECBPG2PTR  ECBBASEPTR + 0x1000
72278724Sdim#define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16))
73278724Sdim#define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
74278724Sdim
75278724Sdim#if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
76278724Sdim# define __gthrw(name) \
77278724Sdim  extern __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
78278724Sdim# define __gthrw_(name) __gthrw_ ## name
79278724Sdim#else
80278724Sdim# define __gthrw(name)
81278724Sdim# define __gthrw_(name) name
82278724Sdim#endif
83278724Sdim
84278724Sdim__gthrw(pthread_once)
85278724Sdim__gthrw(pthread_key_create)
86227825Stheraven__gthrw(pthread_key_delete)
87227825Stheraven__gthrw(pthread_getspecific)
88278724Sdim__gthrw(pthread_setspecific)
89227825Stheraven__gthrw(pthread_create)
90227825Stheraven
91227825Stheraven__gthrw(pthread_mutex_lock)
92227825Stheraven__gthrw(pthread_mutex_trylock)
93227825Stheraven__gthrw(pthread_mutex_unlock)
94227825Stheraven
95227825Stheravenstatic inline int
96227825Stheraven__gthread_active_p (void)
97227825Stheraven{
98227825Stheraven  return 1;
99227825Stheraven}
100227825Stheraven
101278724Sdimstatic inline int
102278724Sdim__gthread_once (__gthread_once_t *once, void (*func) (void))
103278724Sdim{
104278724Sdim  if (__tpf_pthread_active ())
105278724Sdim    return __gthrw_(pthread_once) (once, func);
106278724Sdim  else
107278724Sdim    return -1;
108278724Sdim}
109278724Sdim
110278724Sdimstatic inline int
111278724Sdim__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
112278724Sdim{
113278724Sdim  if (__tpf_pthread_active ())
114278724Sdim    return __gthrw_(pthread_key_create) (key, dtor);
115278724Sdim  else
116278724Sdim    return -1;
117227825Stheraven}
118227825Stheraven
119227825Stheravenstatic inline int
120278724Sdim__gthread_key_delete (__gthread_key_t key)
121278724Sdim{
122227825Stheraven  if (__tpf_pthread_active ())
123241903Sdim    return __gthrw_(pthread_key_delete) (key);
124227825Stheraven  else
125227825Stheraven    return -1;
126227825Stheraven}
127227825Stheraven
128227825Stheravenstatic 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