IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31579


Ignore:
Timestamp:
May 27, 2011, 10:59:56 AM (15 years ago)
Author:
eugene
Message:

clean up spinlock / hardlock options for psMemory.c

Location:
branches/eam_branches/ipp-20110505/psLib/src/sys
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110505/psLib/src/sys/psMemory.c

    r31576 r31579  
    4040#define P_PS_MEMMAGIC (uint32_t)0xdeadbeef
    4141
    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
    4359
    4460# if (USE_SPINLOCK)
     
    110126static pthread_spinlock_t memBlockListMutex;
    111127# else
    112 // static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
    113 static pthread_mutex_t memBlockListMutex;
     128static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
    114129# endif
    115130
     
    118133# if (USE_SPINLOCK)
    119134    pthread_spin_init(&memBlockListMutex, 0);
    120 # else
    121     pthread_mutex_init(&memBlockListMutex, NULL);
    122135# endif
    123136
     
    359372 **/
    360373
    361 // if HARDLOCKS is set, revert to global locking for realloc
    362 # define HARDLOCKS 0
    363 
    364 # if (!HARDLOCKS)
     374# if (!USE_HARDLOCK)
    365375static int setLock = 0;
    366376static int clearLock = 0;
     
    379389void BLOCKLAST_LOCK () {
    380390
    381 # if (HARDLOCKS)
     391# if (USE_HARDLOCK)
    382392    MUTEX_LOCK(&memBlockListMutex);
    383393# else
     
    413423void BLOCK_LOCK (psMemBlock *memBlock, bool keepMutex) {
    414424
    415 # if (HARDLOCKS)
     425# if (USE_HARDLOCK)
    416426    MUTEX_LOCK(&memBlockListMutex);
    417427# else
     
    451461void BLOCK_UNLOCK (psMemBlock *memBlock, bool haveMutex) {
    452462   
    453 # if (HARDLOCKS)
     463# if (USE_HARDLOCK)
    454464    MUTEX_UNLOCK(&memBlockListMutex);
    455465# else
     
    481491void BLOCKSET_LOCK (psMemBlock *memBlock, bool keepMutex) {
    482492
    483 # if (HARDLOCKS)
     493# if (USE_HARDLOCK)
    484494    MUTEX_LOCK(&memBlockListMutex);
    485495# else
     
    539549void BLOCKSET_UNLOCK (psMemBlock *memBlock, bool haveMutex) {
    540550   
    541 # if (HARDLOCKS)
     551# if (USE_HARDLOCK)
    542552    MUTEX_UNLOCK(&memBlockListMutex);
    543553# else
  • branches/eam_branches/ipp-20110505/psLib/src/sys/psMemory.h

    r31576 r31579  
    146146#endif // ifdef DOXYGEN
    147147
     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)
    148150void psMemInit(void);
    149151
Note: See TracChangeset for help on using the changeset viewer.