# gthr-tpf.h

    00001 /* Threads compatibility routines for libgcc2 and libobjc.
    00002    Compile this one with gcc.
    00003    Copyright (C) 2004 Free Software Foundation, Inc.
    00004
    00005 This file is part of GCC.
    00006
    00007 GCC is free software; you can redistribute it and/or modify it under
    00008 the terms of the GNU General Public License as published by the Free
    00009 Software Foundation; either version 2, or (at your option) any later
    00010 version.
    00011
    00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
    00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    00015 for more details.
    00016
    00017 You should have received a copy of the GNU General Public License
    00018 along with GCC; see the file COPYING.  If not, write to the Free
    00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    00020 02111-1307, USA.  */
    00021
    00022 /* As a special exception, if you link this library with other files,
    00023    some of which are compiled with GCC, to produce an executable,
    00024    this library does not by itself cause the resulting executable
    00025    to be covered by the GNU General Public License.
    00026    This exception does not however invalidate any other reasons why
    00027    the executable file might be covered by the GNU General Public License.  */
    00028
    00029
    00030 /* TPF needs its own version of gthr-*.h because TPF always links to
    00031    the thread library.  However, for performance reasons we still do not
    00032    want to issue thread api calls unless a check is made to see that we
    00033    are running as a thread.  */
    00034
    00035 #ifndef _GLIBCXX_GCC_GTHR_TPF_H
    00036 #define _GLIBCXX_GCC_GTHR_TPF_H
    00037
    00038 /* POSIX threads specific definitions.
    00039    Easy, since the interface is just one-to-one mapping.  */
    00040
    00041 #define __GTHREADS 1
    00042
    00043 /* Some implementations of <pthread.h> require this to be defined.  */
    00044 #ifndef _REENTRANT
    00045 #define _REENTRANT 1
    00046 #endif
    00047
    00048 #include <pthread.h>
    00049 #include <unistd.h>
    00050
    00051 typedef pthread_key_t __gthread_key_t;
    00052 typedef pthread_once_t __gthread_once_t;
    00053 typedef pthread_mutex_t __gthread_mutex_t;
    00054 typedef pthread_mutex_t __gthread_recursive_mutex_t;
    00055
    00056 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
    00057 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
    00058 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
    00059 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
    00060 #endif
    00061
    00062 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
    00063 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
    00064
    00065 #define NOTATHREAD   00
    00066 #define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
    00067 #define ECBPG2PTR  ECBBASEPTR + 0x1000
    00068 #define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 208))
    00069 #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
    00070
    00071 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
    00072
    00073 #pragma weak pthread_once
    00074 #pragma weak pthread_key_create
    00075 #pragma weak pthread_key_delete
    00076 #pragma weak pthread_getspecific
    00077 #pragma weak pthread_setspecific
    00078 #pragma weak pthread_create
    00079
    00080 #pragma weak pthread_mutex_lock
    00081 #pragma weak pthread_mutex_trylock
    00082 #pragma weak pthread_mutex_unlock
    00083
    00084 #endif /* __GXX_WEAK__ */
    00085
    00086 static inline int
    00087 __gthread_active_p (void)
    00088 {
    00089   return 1;
    00090 }
    00091
    00092 static inline int
    00093 __gthread_once (__gthread_once_t *once, void (*func) (void))
    00094 {
    00095   if (__tpf_pthread_active ())
    00096     return pthread_once (once, func);
    00097   else
    00098     return -1;
    00099 }
    00100
    00101 static inline int
    00102 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
    00103 {
    00104   if (__tpf_pthread_active ())
    00105     return pthread_key_create (key, dtor);
    00106   else
    00107     return -1;
    00108 }
    00109
    00110 static inline int
    00111 __gthread_key_delete (__gthread_key_t key)
    00112 {
    00113   if (__tpf_pthread_active ())
    00114     return pthread_key_delete (key);
    00115   else
    00116     return -1;
    00117 }
    00118
    00119 static inline void *
    00120 __gthread_getspecific (__gthread_key_t key)
    00121 {
    00122   if (__tpf_pthread_active ())
    00123     return pthread_getspecific (key);
    00124   else
    00125     return NULL;
    00126 }
    00127
    00128 static inline int
    00129 __gthread_setspecific (__gthread_key_t key, const void *ptr)
    00130 {
    00131   if (__tpf_pthread_active ())
    00132     return pthread_setspecific (key, ptr);
    00133   else
    00134     return -1;
    00135 }
    00136
    00137 static inline int
    00138 __gthread_mutex_lock (__gthread_mutex_t *mutex)
    00139 {
    00140   if (__tpf_pthread_active ())
    00141     return pthread_mutex_lock (mutex);
    00142   else
    00143     return 0;
    00144 }
    00145
    00146 static inline int
    00147 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
    00148 {
    00149   if (__tpf_pthread_active ())
    00150     return pthread_mutex_trylock (mutex);
    00151   else
    00152     return 0;
    00153 }
    00154
    00155 static inline int
    00156 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
    00157 {
    00158   if (__tpf_pthread_active ())
    00159     return pthread_mutex_unlock (mutex);
    00160   else
    00161     return 0;
    00162 }
    00163
    00164 static inline int
    00165 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
    00166 {
    00167   if (__tpf_pthread_active ())
    00168     return __gthread_mutex_lock (mutex);
    00169   else
    00170     return 0;
    00171 }
    00172
    00173 static inline int
    00174 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
    00175 {
    00176   if (__tpf_pthread_active ())
    00177     return __gthread_mutex_trylock (mutex);
    00178   else
    00179     return 0;
    00180 }
    00181
    00182 static inline int
    00183 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
    00184 {
    00185   if (__tpf_pthread_active ())
    00186     return __gthread_mutex_unlock (mutex);
    00187   else
    00188     return 0;
    00189 }
    00190
    00191 #endif /* ! _GLIBCXX_GCC_GTHR_TPF_H */