Changeset 5055
- Timestamp:
- 12/02/07 20:54:01 (1 year ago)
- Files:
-
- libwired/trunk/libwired/thread/wi-thread.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/thread/wi-thread.c
r4623 r5055 70 70 #ifdef WI_PTHREADS 71 71 static pthread_key_t _wi_thread_hash_key; 72 static pthread_key_t _wi_thread_thread_key; 73 #else 74 static wi_hash_t *_wi_thread_hash; 75 static wi_thread_t *_wi_thread_thread; 72 76 #endif 73 77 … … 92 96 void wi_thread_initialize(void) { 93 97 #ifdef WI_PTHREADS 94 pthread_key_create(&_wi_thread_hash_key, wi_release); 98 pthread_key_create(&_wi_thread_hash_key, NULL); 99 pthread_key_create(&_wi_thread_thread_key, NULL); 95 100 #endif 96 101 … … 180 185 static void * _wi_thread_trampoline(void *arg) { 181 186 void **vector = (void **) arg; 187 wi_hash_t *hash; 182 188 wi_thread_func_t *function; 183 189 wi_runtime_instance_t *argument; … … 189 195 190 196 wi_thread_enter_thread(); 191 197 192 198 (*function)(argument); 193 199 194 200 wi_thread_exit_thread(); 195 201 196 202 wi_release(argument); 197 203 … … 204 210 void wi_thread_enter_thread(void) { 205 211 wi_thread_t *thread; 212 wi_pool_t *pool; 206 213 207 214 thread = _wi_thread_init(_wi_thread_alloc()); 215 208 216 #ifdef WI_PTHREADS 209 217 thread->thread = pthread_self(); 210 218 #endif 211 wi_hash_set_data_for_key(wi_thread_hash(), thread, WI_STR(_WI_THREAD_KEY)); 212 wi_release(thread); 219 220 #ifdef WI_PTHREADS 221 pthread_setspecific(_wi_thread_thread_key, thread); 222 #else 223 _wi_thread_thread = thread; 224 #endif 213 225 214 226 wi_error_enter_thread(); … … 218 230 219 231 void wi_thread_exit_thread(void) { 232 wi_hash_t *hash; 233 wi_thread_t *thread; 234 220 235 wi_socket_exit_thread(); 236 237 wi_release(wi_thread_hash()); 238 wi_release(wi_thread_current_thread()); 221 239 } 222 240 … … 226 244 227 245 wi_thread_t * wi_thread_current_thread(void) { 228 return wi_hash_data_for_key(wi_thread_hash(), WI_STR(_WI_THREAD_KEY)); 246 #ifdef WI_PTHREADS 247 return pthread_getspecific(_wi_thread_thread_key); 248 #else 249 return _wi_thread_thread; 250 #endif 229 251 } 230 252 … … 245 267 return hash; 246 268 #else 247 static wi_hash_t *hash; 248 249 if(!hash) 250 hash = wi_hash_init(wi_hash_alloc()); 251 252 return hash; 269 if(!_wi_thread_hash) 270 _wi_thread_hash = wi_hash_init(wi_hash_alloc()); 271 272 return _wi_thread_hash; 253 273 #endif 254 274 }
