gthr-tpf.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _GLIBCXX_GCC_GTHR_TPF_H
00036 #define _GLIBCXX_GCC_GTHR_TPF_H
00037
00038
00039
00040
00041 #define __GTHREADS 1
00042
00043
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