Changeset 31579
- Timestamp:
- May 27, 2011, 10:59:56 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110505/psLib/src/sys
- Files:
-
- 2 edited
-
psMemory.c (modified) (9 diffs)
-
psMemory.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110505/psLib/src/sys/psMemory.c
r31576 r31579 40 40 #define P_PS_MEMMAGIC (uint32_t)0xdeadbeef 41 41 42 # define USE_SPINLOCK 1 42 // The psLib memory tools require locking to manipulate the linked list which holds the memory 43 // structure. There are two major options which can be invoked, given below. 44 45 // USE_SPINLOCK replaces the mutex in this code block with a spinlock. This might be faster in 46 // some cases, but probably not enough to matter. The disadavantages are: (1) programs would 47 // need to call the function 'psMemInit' (which they currently do not in general); (2) 48 // single-processor machines are poorly set up to use spinlocks; (3) not all compilers / 49 // machine combinations support spinlocks. This option is NOT recommended 50 51 // USE_HARDLOCK replaces the per-memBlock locking that is the minimum required to protect the 52 // psRealloc function with pure mutex locking that holds the lock during the (possibly 53 // expensive) realloc call. At this point, it does not seem clear that there is a substantial 54 // gain in processing speed from using the per-memBlock locking, but more testing may reveal 55 // cases where it matters. 56 57 # define USE_SPINLOCK 0 58 # define USE_HARDLOCK 0 43 59 44 60 # if (USE_SPINLOCK) … … 110 126 static pthread_spinlock_t memBlockListMutex; 111 127 # else 112 // static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER; 113 static pthread_mutex_t memBlockListMutex; 128 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER; 114 129 # endif 115 130 … … 118 133 # if (USE_SPINLOCK) 119 134 pthread_spin_init(&memBlockListMutex, 0); 120 # else121 pthread_mutex_init(&memBlockListMutex, NULL);122 135 # endif 123 136 … … 359 372 **/ 360 373 361 // if HARDLOCKS is set, revert to global locking for realloc 362 # define HARDLOCKS 0 363 364 # if (!HARDLOCKS) 374 # if (!USE_HARDLOCK) 365 375 static int setLock = 0; 366 376 static int clearLock = 0; … … 379 389 void BLOCKLAST_LOCK () { 380 390 381 # if ( HARDLOCKS)391 # if (USE_HARDLOCK) 382 392 MUTEX_LOCK(&memBlockListMutex); 383 393 # else … … 413 423 void BLOCK_LOCK (psMemBlock *memBlock, bool keepMutex) { 414 424 415 # if ( HARDLOCKS)425 # if (USE_HARDLOCK) 416 426 MUTEX_LOCK(&memBlockListMutex); 417 427 # else … … 451 461 void BLOCK_UNLOCK (psMemBlock *memBlock, bool haveMutex) { 452 462 453 # if ( HARDLOCKS)463 # if (USE_HARDLOCK) 454 464 MUTEX_UNLOCK(&memBlockListMutex); 455 465 # else … … 481 491 void BLOCKSET_LOCK (psMemBlock *memBlock, bool keepMutex) { 482 492 483 # if ( HARDLOCKS)493 # if (USE_HARDLOCK) 484 494 MUTEX_LOCK(&memBlockListMutex); 485 495 # else … … 539 549 void BLOCKSET_UNLOCK (psMemBlock *memBlock, bool haveMutex) { 540 550 541 # if ( HARDLOCKS)551 # if (USE_HARDLOCK) 542 552 MUTEX_UNLOCK(&memBlockListMutex); 543 553 # else -
branches/eam_branches/ipp-20110505/psLib/src/sys/psMemory.h
r31576 r31579 146 146 #endif // ifdef DOXYGEN 147 147 148 // if we decide to use spinlocks for psMemory, it will be necessary to call this function at 149 // the start of every psLib-based program (spinlocks do not have a static initializer) 148 150 void psMemInit(void); 149 151
Note:
See TracChangeset
for help on using the changeset viewer.
