1 /* This file is automatically generated. DO NOT EDIT! */ 2 /* Generated from: NetBSD: mknative-gcc,v 1.59 2011/07/03 06:47:12 mrg Exp */ 3 /* Generated from: NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp */ 4 5 /* Threads compatibility routines for libgcc2 and libobjc. 6 Compile this one with gcc. 7 Copyright (C) 2004, 2005, 2008, 2009 Free Software Foundation, Inc. 8 9 This file is part of GCC. 10 11 GCC is free software; you can redistribute it and/or modify it under 12 the terms of the GNU General Public License as published by the Free 13 Software Foundation; either version 3, or (at your option) any later 14 version. 15 16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 for more details. 20 21 Under Section 7 of GPL version 3, you are granted additional 22 permissions described in the GCC Runtime Library Exception, version 23 3.1, as published by the Free Software Foundation. 24 25 You should have received a copy of the GNU General Public License and 26 a copy of the GCC Runtime Library Exception along with this program; 27 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 28 <http://www.gnu.org/licenses/>. */ 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 _GLIBCXX_GCC_GTHR_TPF_H 36 #define _GLIBCXX_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 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function 65 66 #define NOTATHREAD 00 67 #define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u 68 #define ECBPG2PTR ECBBASEPTR + 0x1000 69 #define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16)) 70 #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD) 71 72 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK 73 # define __gthrw(name) \ 74 static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name))); 75 # define __gthrw_(name) __gthrw_ ## name 76 #else 77 # define __gthrw(name) 78 # define __gthrw_(name) name 79 #endif 80 81 __gthrw(pthread_once) 82 __gthrw(pthread_key_create) 83 __gthrw(pthread_key_delete) 84 __gthrw(pthread_getspecific) 85 __gthrw(pthread_setspecific) 86 __gthrw(pthread_create) 87 88 __gthrw(pthread_mutex_lock) 89 __gthrw(pthread_mutex_trylock) 90 __gthrw(pthread_mutex_unlock) 91 __gthrw(pthread_mutexattr_init) 92 __gthrw(pthread_mutexattr_settype) 93 __gthrw(pthread_mutexattr_destroy) 94 __gthrw(pthread_mutex_init) 95 __gthrw(pthread_mutex_destroy) 96 97 static inline int 98 __gthread_active_p (void) 99 { 100 return 1; 101 } 102 103 static inline int 104 __gthread_once (__gthread_once_t *__once, void (*__func) (void)) 105 { 106 if (__tpf_pthread_active ()) 107 return __gthrw_(pthread_once) (__once, __func); 108 else 109 return -1; 110 } 111 112 static inline int 113 __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) 114 { 115 if (__tpf_pthread_active ()) 116 return __gthrw_(pthread_key_create) (__key, __dtor); 117 else 118 return -1; 119 } 120 121 static inline int 122 __gthread_key_delete (__gthread_key_t __key) 123 { 124 if (__tpf_pthread_active ()) 125 return __gthrw_(pthread_key_delete) (__key); 126 else 127 return -1; 128 } 129 130 static inline void * 131 __gthread_getspecific (__gthread_key_t __key) 132 { 133 if (__tpf_pthread_active ()) 134 return __gthrw_(pthread_getspecific) (__key); 135 else 136 return NULL; 137 } 138 139 static inline int 140 __gthread_setspecific (__gthread_key_t __key, const void *__ptr) 141 { 142 if (__tpf_pthread_active ()) 143 return __gthrw_(pthread_setspecific) (__key, __ptr); 144 else 145 return -1; 146 } 147 148 static inline int 149 __gthread_mutex_destroy (__gthread_mutex_t *__mutex) 150 { 151 if (__tpf_pthread_active ()) 152 return __gthrw_(pthread_mutex_destroy) (__mutex); 153 else 154 return 0; 155 } 156 157 static inline int 158 __gthread_mutex_lock (__gthread_mutex_t *__mutex) 159 { 160 if (__tpf_pthread_active ()) 161 return __gthrw_(pthread_mutex_lock) (__mutex); 162 else 163 return 0; 164 } 165 166 static inline int 167 __gthread_mutex_trylock (__gthread_mutex_t *__mutex) 168 { 169 if (__tpf_pthread_active ()) 170 return __gthrw_(pthread_mutex_trylock) (__mutex); 171 else 172 return 0; 173 } 174 175 static inline int 176 __gthread_mutex_unlock (__gthread_mutex_t *__mutex) 177 { 178 if (__tpf_pthread_active ()) 179 return __gthrw_(pthread_mutex_unlock) (__mutex); 180 else 181 return 0; 182 } 183 184 static inline int 185 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) 186 { 187 if (__tpf_pthread_active ()) 188 return __gthread_mutex_lock (__mutex); 189 else 190 return 0; 191 } 192 193 static inline int 194 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) 195 { 196 if (__tpf_pthread_active ()) 197 return __gthread_mutex_trylock (__mutex); 198 else 199 return 0; 200 } 201 202 static inline int 203 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) 204 { 205 if (__tpf_pthread_active ()) 206 return __gthread_mutex_unlock (__mutex); 207 else 208 return 0; 209 } 210 211 static inline int 212 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex) 213 { 214 if (__tpf_pthread_active ()) 215 { 216 pthread_mutexattr_t __attr; 217 int __r; 218 219 __r = __gthrw_(pthread_mutexattr_init) (&__attr); 220 if (!__r) 221 __r = __gthrw_(pthread_mutexattr_settype) (&__attr, 222 PTHREAD_MUTEX_RECURSIVE); 223 if (!__r) 224 __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr); 225 if (!__r) 226 __r = __gthrw_(pthread_mutexattr_destroy) (&__attr); 227 return __r; 228 } 229 return 0; 230 } 231 232 233 #endif /* ! _GLIBCXX_GCC_GTHR_TPF_H */ 234