IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6425 for trunk/psLib/src/types


Ignore:
Timestamp:
Feb 13, 2006, 2:09:27 PM (20 years ago)
Author:
drobbin
Message:

Added psMemThreadSafety. Removed p_lock from psList. Added comments and made minor changes to EOC.

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

Legend:

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

    r6419 r6425  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-02-10 02:44:46 $
     8 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-02-14 00:09:27 $
    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.
    36 static bool safeThreads = true;
    37 
    3835static void listFree(psList* list)
    3936{
    4037    if (list == NULL) {
    4138        return;
    42     }
    43 
    44     if (safeThreads) {
    45         pthread_mutex_lock(&list->p_lock);
    46         //        pthread_mutex_lock(&p_lock);
    4739    }
    4840
     
    6961        ptr = next;
    7062    }
    71 
    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     }
    8063}
    8164
     
    11093    int index = iterator->index;
    11194
    112     if (safeThreads) {
    113         pthread_mutex_lock(&list->p_lock);
    114         //        pthread_mutex_lock(&p_lock);
    115     }
    11695    if (elem == list->head) {        // head of list?
    11796        list->head = elem->next;
     
    138117    list->n--;
    139118
    140     if (safeThreads) {
    141         pthread_mutex_unlock(&list->p_lock);
    142         //        pthread_mutex_unlock(&p_lock);
    143     }
    144 
    145119    // OK, delete orphaned list element and its data
    146120    psFree(elem->data);
     
    164138    psListIteratorAlloc(list,PS_LIST_HEAD,true);
    165139
    166     if (safeThreads) {
    167         pthread_mutex_init(&(list->p_lock), NULL);
    168         //        pthread_mutex_init(&p_lock, NULL);
    169     }
    170 
    171140    if (data != NULL) {
    172141        psListAdd(list, PS_LIST_TAIL, data);
     
    179148{
    180149    return ( psMemGetDeallocator(ptr) == (psFreeFunc)listFree );
    181 }
    182 
    183 bool p_psListThreadSafety(bool safe)
    184 {
    185     bool out = safeThreads;
    186     safeThreads = safe;
    187     return out;
    188150}
    189151
     
    347309
    348310    psListElem* elem = psAlloc(sizeof(psListElem));
    349 
    350     if (safeThreads) {
    351         pthread_mutex_lock(&list->p_lock);
    352         //        pthread_mutex_lock(&p_lock);
    353     }
    354311
    355312    // set the new list element's attributes
     
    387344    }
    388345
    389     if (safeThreads) {
    390         pthread_mutex_unlock(&list->p_lock);
    391         //        pthread_mutex_unlock(&p_lock);
    392     }
    393 
    394346    return true;
    395347}
     
    426378
    427379    psListElem* elem = psAlloc(sizeof(psListElem));
    428 
    429     if (safeThreads) {
    430         pthread_mutex_lock(&list->p_lock);
    431         //        pthread_mutex_lock(&p_lock);
    432     }
    433380
    434381    // set the new list element's attributes
     
    466413    }
    467414
    468     if (safeThreads) {
    469         pthread_mutex_unlock(&list->p_lock);
    470         //        pthread_mutex_unlock(&p_lock);
    471     }
    472 
    473415    return true;
    474416}
  • trunk/psLib/src/types/psList.h

    r6419 r6425  
    77 *  @ingroup LinkedList
    88 *
    9  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-02-10 02:44:46 $
     9 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-02-14 00:09:27 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5959    ///< used internally to improve performance when using indexed access, all
    6060    ///< others are user-level iterators created by psListIteratorAlloc.
    61     pthread_mutex_t p_lock;            ///< mutex to lock a node during changes
    6261    void *lock;                        ///< Optional lock for thread safety
    6362}
     
    9493;
    9594
    96 /** Private function used by psMemThreadSafety to activate/deactivate thread safety.
    97  *
    98  *  @return bool:       The previous value of the thread safety.
    99  */
    100 bool p_psListThreadSafety(
    101     bool safe                          ///< current value of thread safety to set
    102 );
    103 
    10495/** Creates a psList linked list object.
    10596 *
Note: See TracChangeset for help on using the changeset viewer.