Changeset 6425 for trunk/psLib/src/types
- Timestamp:
- Feb 13, 2006, 2:09:27 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psList.c
r6419 r6425 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.4 6$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-02-1 0 02:44:46$8 * @version $Revision: 1.47 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-02-14 00:09:27 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 33 33 static psBool listIteratorRemove(psListIterator* iterator); 34 34 35 //private boolean for enabling/disabling thread safety. Default = enabled.36 static bool safeThreads = true;37 38 35 static void listFree(psList* list) 39 36 { 40 37 if (list == NULL) { 41 38 return; 42 }43 44 if (safeThreads) {45 pthread_mutex_lock(&list->p_lock);46 // pthread_mutex_lock(&p_lock);47 39 } 48 40 … … 69 61 ptr = next; 70 62 } 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 }80 63 } 81 64 … … 110 93 int index = iterator->index; 111 94 112 if (safeThreads) {113 pthread_mutex_lock(&list->p_lock);114 // pthread_mutex_lock(&p_lock);115 }116 95 if (elem == list->head) { // head of list? 117 96 list->head = elem->next; … … 138 117 list->n--; 139 118 140 if (safeThreads) {141 pthread_mutex_unlock(&list->p_lock);142 // pthread_mutex_unlock(&p_lock);143 }144 145 119 // OK, delete orphaned list element and its data 146 120 psFree(elem->data); … … 164 138 psListIteratorAlloc(list,PS_LIST_HEAD,true); 165 139 166 if (safeThreads) {167 pthread_mutex_init(&(list->p_lock), NULL);168 // pthread_mutex_init(&p_lock, NULL);169 }170 171 140 if (data != NULL) { 172 141 psListAdd(list, PS_LIST_TAIL, data); … … 179 148 { 180 149 return ( psMemGetDeallocator(ptr) == (psFreeFunc)listFree ); 181 }182 183 bool p_psListThreadSafety(bool safe)184 {185 bool out = safeThreads;186 safeThreads = safe;187 return out;188 150 } 189 151 … … 347 309 348 310 psListElem* elem = psAlloc(sizeof(psListElem)); 349 350 if (safeThreads) {351 pthread_mutex_lock(&list->p_lock);352 // pthread_mutex_lock(&p_lock);353 }354 311 355 312 // set the new list element's attributes … … 387 344 } 388 345 389 if (safeThreads) {390 pthread_mutex_unlock(&list->p_lock);391 // pthread_mutex_unlock(&p_lock);392 }393 394 346 return true; 395 347 } … … 426 378 427 379 psListElem* elem = psAlloc(sizeof(psListElem)); 428 429 if (safeThreads) {430 pthread_mutex_lock(&list->p_lock);431 // pthread_mutex_lock(&p_lock);432 }433 380 434 381 // set the new list element's attributes … … 466 413 } 467 414 468 if (safeThreads) {469 pthread_mutex_unlock(&list->p_lock);470 // pthread_mutex_unlock(&p_lock);471 }472 473 415 return true; 474 416 } -
trunk/psLib/src/types/psList.h
r6419 r6425 7 7 * @ingroup LinkedList 8 8 * 9 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-02-1 0 02:44:46$9 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-02-14 00:09:27 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 59 59 ///< used internally to improve performance when using indexed access, all 60 60 ///< others are user-level iterators created by psListIteratorAlloc. 61 pthread_mutex_t p_lock; ///< mutex to lock a node during changes62 61 void *lock; ///< Optional lock for thread safety 63 62 } … … 94 93 ; 95 94 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 set102 );103 104 95 /** Creates a psList linked list object. 105 96 *
Note:
See TracChangeset
for help on using the changeset viewer.
