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 #ifndef _THREAD_M_H
00028 #define _THREAD_M_H
00029
00030 #undef thread_atfork_static
00031
00032 #if defined(_LIBC)
00033
00034 #include <bits/libc-lock.h>
00035
00036 #ifdef PTHREAD_MUTEX_INITIALIZER
00037
00038 typedef pthread_t thread_id;
00039
00040
00041 typedef pthread_mutex_t mutex_t;
00042
00043 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
00044
00045
00046
00047
00048
00049 #define mutex_init(m) \
00050 (__pthread_mutex_init != NULL \
00051 ? __pthread_mutex_init (m, NULL) : (*(int *)(m) = 0))
00052 #define mutex_lock(m) \
00053 (__pthread_mutex_lock != NULL \
00054 ? __pthread_mutex_lock (m) : ((*(int *)(m) = 1), 0))
00055 #define mutex_trylock(m) \
00056 (__pthread_mutex_trylock != NULL \
00057 ? __pthread_mutex_trylock (m) : (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
00058 #define mutex_unlock(m) \
00059 (__pthread_mutex_unlock != NULL \
00060 ? __pthread_mutex_unlock (m) : (*(int*)(m) = 0))
00061
00062 #define thread_atfork(prepare, parent, child) \
00063 (__pthread_atfork != NULL ? __pthread_atfork(prepare, parent, child) : 0)
00064
00065 #elif defined(MUTEX_INITIALIZER)
00066
00067
00068
00069
00070 #undef mutex_t
00071 #define mutex_t struct mutex
00072
00073 #undef mutex_init
00074 #define mutex_init(m) (__mutex_init(m), 0)
00075
00076 #undef mutex_lock
00077 #define mutex_lock(m) (__mutex_lock(m), 0)
00078
00079 #undef mutex_unlock
00080 #define mutex_unlock(m) (__mutex_unlock(m), 0)
00081
00082 #define mutex_trylock(m) (!__mutex_trylock(m))
00083
00084 #define thread_atfork(prepare, parent, child) do {} while(0)
00085 #define thread_atfork_static(prepare, parent, child) \
00086 text_set_element(_hurd_fork_prepare_hook, prepare); \
00087 text_set_element(_hurd_fork_parent_hook, parent); \
00088 text_set_element(_hurd_fork_child_hook, child);
00089
00090
00091 #define __pthread_initialize ((void (*)(void))0)
00092
00093 #else
00094
00095 #define NO_THREADS
00096
00097 #endif
00098
00099 #ifndef NO_THREADS
00100
00101
00102
00103 #include <bits/libc-tsd.h>
00104
00105 typedef int tsd_key_t[1];
00106 __libc_tsd_define (, MALLOC)
00107 #define tsd_key_create(key, destr) ((void) (key))
00108 #define tsd_setspecific(key, data) __libc_tsd_set (MALLOC, (data))
00109 #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (MALLOC))
00110
00111 #endif
00112
00113 #elif defined(USE_PTHREADS)
00114
00115 #include <pthread.h>
00116
00117 typedef pthread_t thread_id;
00118
00119
00120 typedef pthread_mutex_t mutex_t;
00121
00122 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
00123 #define mutex_init(m) pthread_mutex_init(m, NULL)
00124 #define mutex_lock(m) pthread_mutex_lock(m)
00125 #define mutex_trylock(m) pthread_mutex_trylock(m)
00126 #define mutex_unlock(m) pthread_mutex_unlock(m)
00127
00128
00129 #if defined(__sgi) || defined(USE_TSD_DATA_HACK)
00130
00131
00132
00133
00134
00135
00136 typedef void *tsd_key_t[256];
00137 #define tsd_key_create(key, destr) do { \
00138 int i; \
00139 for(i=0; i<256; i++) (*key)[i] = 0; \
00140 } while(0)
00141 #define tsd_setspecific(key, data) \
00142 (key[(unsigned)pthread_self() % 256] = (data))
00143 #define tsd_getspecific(key, vptr) \
00144 (vptr = key[(unsigned)pthread_self() % 256])
00145
00146 #else
00147
00148 typedef pthread_key_t tsd_key_t;
00149
00150 #define tsd_key_create(key, destr) pthread_key_create(key, destr)
00151 #define tsd_setspecific(key, data) pthread_setspecific(key, data)
00152 #define tsd_getspecific(key, vptr) (vptr = pthread_getspecific(key))
00153
00154 #endif
00155
00156
00157 #define thread_atfork(prepare, parent, child) \
00158 pthread_atfork(prepare, parent, child)
00159
00160 #elif USE_THR
00161
00162 #include <thread.h>
00163
00164 typedef thread_t thread_id;
00165
00166 #define MUTEX_INITIALIZER { 0 }
00167 #define mutex_init(m) mutex_init(m, USYNC_THREAD, NULL)
00168
00169
00170
00171
00172
00173 typedef void *tsd_key_t[256];
00174 #define tsd_key_create(key, destr) do { \
00175 int i; \
00176 for(i=0; i<256; i++) (*key)[i] = 0; \
00177 } while(0)
00178 #define tsd_setspecific(key, data) (key[(unsigned)thr_self() % 256] = (data))
00179 #define tsd_getspecific(key, vptr) (vptr = key[(unsigned)thr_self() % 256])
00180
00181 #define thread_atfork(prepare, parent, child) do {} while(0)
00182
00183 #elif USE_SPROC
00184
00185 #include <sys/wait.h>
00186 #include <sys/types.h>
00187 #include <sys/prctl.h>
00188 #include <abi_mutex.h>
00189
00190 typedef int thread_id;
00191
00192 typedef abilock_t mutex_t;
00193
00194 #define MUTEX_INITIALIZER { 0 }
00195 #define mutex_init(m) init_lock(m)
00196 #define mutex_lock(m) (spin_lock(m), 0)
00197 #define mutex_trylock(m) acquire_lock(m)
00198 #define mutex_unlock(m) release_lock(m)
00199
00200 typedef int tsd_key_t;
00201 int tsd_key_next;
00202 #define tsd_key_create(key, destr) ((*key) = tsd_key_next++)
00203 #define tsd_setspecific(key, data) (((void **)(&PRDA->usr_prda))[key] = data)
00204 #define tsd_getspecific(key, vptr) (vptr = ((void **)(&PRDA->usr_prda))[key])
00205
00206 #define thread_atfork(prepare, parent, child) do {} while(0)
00207
00208 #else
00209
00210 #define NO_THREADS
00211
00212 #endif
00213
00214 #ifdef NO_THREADS
00215
00216 typedef int thread_id;
00217
00218
00219
00220
00221
00222
00223
00224 typedef int mutex_t;
00225
00226 #define MUTEX_INITIALIZER 0
00227 #define mutex_init(m) (*(m) = 0)
00228 #define mutex_lock(m) ((*(m) = 1), 0)
00229 #define mutex_trylock(m) (*(m) ? 1 : ((*(m) = 1), 0))
00230 #define mutex_unlock(m) (*(m) = 0)
00231
00232 typedef void *tsd_key_t;
00233 #define tsd_key_create(key, destr) do {} while(0)
00234 #define tsd_setspecific(key, data) ((key) = (data))
00235 #define tsd_getspecific(key, vptr) (vptr = (key))
00236
00237 #define thread_atfork(prepare, parent, child) do {} while(0)
00238
00239 #endif
00240
00241 #endif