gthr-tpf.h

Go to the documentation of this file.
00001 /* Threads compatibility routines for libgcc2 and libobjc.
00002    Compile this one with gcc.
00003    Copyright (C) 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA
00020 02110-1301, 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 + 16))
00069 #define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
00070 
00071 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
00072 # define __gthrw(name) \
00073   extern __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
00074 # define __gthrw_(name) __gthrw_ ## name
00075 #else
00076 # define __gthrw(name)
00077 # define __gthrw_(name) name
00078 #endif
00079 
00080 __gthrw(pthread_once)
00081 __gthrw(pthread_key_create)
00082 __gthrw(pthread_key_delete)
00083 __gthrw(pthread_getspecific)
00084 __gthrw(pthread_setspecific)
00085 __gthrw(pthread_create)
00086 
00087 __gthrw(pthread_mutex_lock)
00088 __gthrw(pthread_mutex_trylock)
00089 __gthrw(pthread_mutex_unlock)
00090 
00091 static inline int
00092 __gthread_active_p (void)
00093 {
00094   return 1;
00095 }
00096 
00097 static inline int
00098 __gthread_once (__gthread_once_t *once, void (*func) (void))
00099 {
00100   if (__tpf_pthread_active ())
00101     return __gthrw_(pthread_once) (once, func);
00102   else
00103     return -1;
00104 }
00105 
00106 static inline int
00107 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
00108 {
00109   if (__tpf_pthread_active ())
00110     return __gthrw_(pthread_key_create) (key, dtor);
00111   else
00112     return -1;
00113 }
00114 
00115 static inline int
00116 __gthread_key_delete (__gthread_key_t key)
00117 {
00118   if (__tpf_pthread_active ())
00119     return __gthrw_(pthread_key_delete) (key);
00120   else
00121     return -1;
00122 }
00123 
00124 static inline void *
00125 __gthread_getspecific (__gthread_key_t key)
00126 {
00127   if (__tpf_pthread_active ())
00128     return __gthrw_(pthread_getspecific) (key);
00129   else
00130     return NULL;
00131 }
00132 
00133 static inline int
00134 __gthread_setspecific (__gthread_key_t key, const void *ptr)
00135 {
00136   if (__tpf_pthread_active ())
00137     return __gthrw_(pthread_setspecific) (key, ptr);
00138   else
00139     return -1;
00140 }
00141 
00142 static inline int
00143 __gthread_mutex_lock (__gthread_mutex_t *mutex)
00144 {
00145   if (__tpf_pthread_active ())
00146     return __gthrw_(pthread_mutex_lock) (mutex);
00147   else
00148     return 0;
00149 }
00150 
00151 static inline int
00152 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
00153 {
00154   if (__tpf_pthread_active ())
00155     return __gthrw_(pthread_mutex_trylock) (mutex);
00156   else
00157     return 0;
00158 }
00159 
00160 static inline int
00161 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
00162 {
00163   if (__tpf_pthread_active ())
00164     return __gthrw_(pthread_mutex_unlock) (mutex);
00165   else
00166     return 0;
00167 }
00168 
00169 static inline int
00170 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
00171 {
00172   if (__tpf_pthread_active ())
00173     return __gthread_mutex_lock (mutex);
00174   else
00175     return 0;
00176 }
00177 
00178 static inline int
00179 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
00180 {
00181   if (__tpf_pthread_active ())
00182     return __gthread_mutex_trylock (mutex);
00183   else
00184     return 0;
00185 }
00186 
00187 static inline int
00188 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
00189 {
00190   if (__tpf_pthread_active ())
00191     return __gthread_mutex_unlock (mutex);
00192   else
00193     return 0;
00194 }
00195 
00196 #endif /* ! _GLIBCXX_GCC_GTHR_TPF_H */

Generated on Tue Feb 2 16:55:58 2010 for GNU C++ STL by  doxygen 1.4.7