Changeset 19057 for trunk/psLib/src/sys/psThread.c
- Timestamp:
- Aug 13, 2008, 5:22:13 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psThread.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psThread.c
r19016 r19057 26 26 static psArray *pool = NULL; // array of defined threads 27 27 static psHash *tasks = NULL; // List of defined tasks 28 static psArray *tsd = NULL; // Thread-specific data 28 29 29 30 … … 165 166 } 166 167 167 bool psThreadTask Delete(const char *type)168 bool psThreadTaskRemove(const char *type) 168 169 { 169 170 PS_ASSERT_STRING_NON_EMPTY(type, false); … … 316 317 tasks = NULL; 317 318 319 psFree(tsd); 320 tsd = NULL; 321 318 322 return true; 319 323 } 320 324 325 326 #if 0 327 // This doesn't work like I thought it would: pthread_self can return anything. 328 bool psThreadDataAdd(const char *name, psPtr ptr) 329 { 330 PS_ASSERT_STRING_NON_EMPTY(name, false); 331 PS_ASSERT_PTR_NON_NULL(ptr, false); 332 333 pthread_key_t *key = psAlloc(sizeof(pthread_key_t)); // Key for data 334 pthread_key_create(key, psFree); 335 336 if (!tsd) { 337 tsd = psArrayAlloc(numThreads); 338 } 339 340 psHashAdd( 341 342 pthread_t tid = pthread_self(); // Thread identifier 343 int numThreads = psThreadPoolSize();// Number of threads 344 psAssert(tid < numThreads, "Thread identifier (%d) exceeds number of threads (%d)", (int)tid, numThreads); 345 346 if (!tsd) { 347 tsd = psArrayAlloc(numThreads); 348 } 349 350 psHash *hash = tsd->data[tid]; // Thread-specific hash of data 351 return psHashAdd(hash, name, ptr); 352 } 353 354 void *psThreadDataLookup(const char *name) 355 { 356 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 357 358 if (!tsd) { 359 return NULL; 360 } 361 362 pthread_t tid = pthread_self(); // Thread identifier 363 int numThreads = psThreadPoolSize();// Number of threads 364 psAssert(tid < numThreads, "Thread identifier (%d) exceeds number of threads (%d)", (int)tid, numThreads); 365 366 psHash *hash = tsd->data[tid]; // Thread-specific hash of data 367 return psHashLookup(hash, name); 368 } 369 370 bool psThreadDataRemove(const char *name) 371 { 372 PS_ASSERT_STRING_NON_EMPTY(name, false); 373 374 if (!tsd) { 375 return false; 376 } 377 378 pthread_t tid = pthread_self(); // Thread identifier 379 int numThreads = psThreadPoolSize();// Number of threads 380 psAssert(tid < numThreads, "Thread identifier (%d) exceeds number of threads (%d)", (int)tid, numThreads); 381 382 psHash *hash = tsd->data[tid]; // Thread-specific hash of data 383 return psHashRemove(hash, name); 384 } 385 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
