IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 13, 2008, 5:22:13 PM (18 years ago)
Author:
Paul Price
Message:

Renamed psThreadTaskDelete to psThreadTaskRemove to maintain consistency with psHash, psMetadata, etc. I'm working on getting some support for thread-specific data. I had a scheme, but it doesn't work (I assumed that a pthread_t was an integer); need to rethink. In the meantime, it's #if-ed out.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psThread.c

    r19016 r19057  
    2626static psArray *pool = NULL;            // array of defined threads
    2727static psHash *tasks = NULL;            // List of defined tasks
     28static psArray *tsd = NULL;             // Thread-specific data
    2829
    2930
     
    165166}
    166167
    167 bool psThreadTaskDelete(const char *type)
     168bool psThreadTaskRemove(const char *type)
    168169{
    169170    PS_ASSERT_STRING_NON_EMPTY(type, false);
     
    316317    tasks = NULL;
    317318
     319    psFree(tsd);
     320    tsd = NULL;
     321
    318322    return true;
    319323}
    320324
     325
     326#if 0
     327// This doesn't work like I thought it would: pthread_self can return anything.
     328bool 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
     354void *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
     370bool 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.