IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6419 for trunk/psLib/src/types


Ignore:
Timestamp:
Feb 9, 2006, 4:44:46 PM (20 years ago)
Author:
drobbin
Message:

Added psMemThreadSafety in psMemory and updated corresponding mutex's to comply with specs.

Location:
trunk/psLib/src/types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psList.c

    r5511 r6419  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-11-14 22:18:34 $
     8 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-02-10 02:44:46 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3333static psBool listIteratorRemove(psListIterator* iterator);
    3434
     35//private boolean for enabling/disabling thread safety.  Default = enabled.
     36static bool safeThreads = true;
     37
    3538static void listFree(psList* list)
    3639{
     
    3942    }
    4043
    41     pthread_mutex_lock(&list->p_lock);
     44    if (safeThreads) {
     45        pthread_mutex_lock(&list->p_lock);
     46        //        pthread_mutex_lock(&p_lock);
     47    }
    4248
    4349    // remove the associated iterators -- any references are invalid once psList is freed.
     
    6470    }
    6571
    66     pthread_mutex_unlock(&list->p_lock);
    67 
    68     pthread_mutex_destroy(&list->p_lock);
    69 
     72    if (safeThreads) {
     73        pthread_mutex_unlock(&list->p_lock);
     74        pthread_mutex_destroy(&list->p_lock);
     75        //        pthread_mutex_unlock(&p_lock);
     76        //        pthread_mutex_destroy(&p_lock);
     77    } else {
     78        safeThreads = true;
     79    }
    7080}
    7181
     
    100110    int index = iterator->index;
    101111
    102     pthread_mutex_lock(&list->p_lock);
    103 
     112    if (safeThreads) {
     113        pthread_mutex_lock(&list->p_lock);
     114        //        pthread_mutex_lock(&p_lock);
     115    }
    104116    if (elem == list->head) {        // head of list?
    105117        list->head = elem->next;
     
    126138    list->n--;
    127139
    128     pthread_mutex_unlock(&list->p_lock)
    129     ;
     140    if (safeThreads) {
     141        pthread_mutex_unlock(&list->p_lock);
     142        //        pthread_mutex_unlock(&p_lock);
     143    }
    130144
    131145    // OK, delete orphaned list element and its data
     
    150164    psListIteratorAlloc(list,PS_LIST_HEAD,true);
    151165
    152     pthread_mutex_init(&(list->p_lock), NULL);
     166    if (safeThreads) {
     167        pthread_mutex_init(&(list->p_lock), NULL);
     168        //        pthread_mutex_init(&p_lock, NULL);
     169    }
    153170
    154171    if (data != NULL) {
     
    164181}
    165182
    166 
     183bool p_psListThreadSafety(bool safe)
     184{
     185    bool out = safeThreads;
     186    safeThreads = safe;
     187    return out;
     188}
    167189
    168190psListIterator* psListIteratorAlloc(psList* list, long location, bool mutable)
     
    326348    psListElem* elem = psAlloc(sizeof(psListElem));
    327349
    328     pthread_mutex_lock(&list->p_lock);
     350    if (safeThreads) {
     351        pthread_mutex_lock(&list->p_lock);
     352        //        pthread_mutex_lock(&p_lock);
     353    }
    329354
    330355    // set the new list element's attributes
     
    362387    }
    363388
    364     pthread_mutex_unlock(&list->p_lock);
     389    if (safeThreads) {
     390        pthread_mutex_unlock(&list->p_lock);
     391        //        pthread_mutex_unlock(&p_lock);
     392    }
    365393
    366394    return true;
     
    399427    psListElem* elem = psAlloc(sizeof(psListElem));
    400428
    401     pthread_mutex_lock(&list->p_lock);
     429    if (safeThreads) {
     430        pthread_mutex_lock(&list->p_lock);
     431        //        pthread_mutex_lock(&p_lock);
     432    }
    402433
    403434    // set the new list element's attributes
     
    435466    }
    436467
    437     pthread_mutex_unlock(&list->p_lock);
     468    if (safeThreads) {
     469        pthread_mutex_unlock(&list->p_lock);
     470        //        pthread_mutex_unlock(&p_lock);
     471    }
    438472
    439473    return true;
  • trunk/psLib/src/types/psList.h

    r6348 r6419  
    77 *  @ingroup LinkedList
    88 *
    9  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-02-07 23:36:15 $
     9 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-02-10 02:44:46 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9494;
    9595
     96/** Private function used by psMemThreadSafety to activate/deactivate thread safety.
     97 *
     98 *  @return bool:       The previous value of the thread safety.
     99 */
     100bool p_psListThreadSafety(
     101    bool safe                          ///< current value of thread safety to set
     102);
    96103
    97104/** Creates a psList linked list object.
Note: See TracChangeset for help on using the changeset viewer.