IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 3:05:30 PM (17 years ago)
Author:
eugene
Message:

added MUTEX around refCounter ++ and --; changed p_psMemAllocID to memAllocID, ditto with p_psMemFreeID (otherwise these look like global private values, but they are local static); cleaned up some old XXX comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psMemory.c

    r19128 r21346  
    1010*  @author Joshua Hoblitt, University of Hawaii
    1111*
    12 *  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2008-08-20 02:00:20 $
     12*  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2009-02-06 01:05:30 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7979//      memFreeCallback -- very rarely accessed
    8080//      memExhaustedCallback -- very rarely accessed
    81 //      p_psMemAllocID -- rarely accessed
    82 //      p_psMemFreeID -- rarely accessed
     81//      memAllocID -- rarely accessed
     82//      memFreeID -- rarely accessed
    8383//      lastMemBlockAllocated
    8484//      memid -- rarely accessby
    8585//      "the linked list of mem blocks"
    8686//
    87 // This is a fair ammount of stuff to protect with a single mutex but most of
     87// This is a fair amount of stuff to protect with a single mutex but most of
    8888// these items are *VERY* low contention items.  The only item that should be
    8989// performance issue is "the linked list of mem blocks".  If this does become a
    90 // problem in production use of the list should be disabled as it is really a
     90// problem in production use of the list could be disabled as it is largely a
    9191// debugging feature.
    9292//
    93 // XXX make the mem block list a build time option
    9493//
    9594static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     
    158157static psMemId memAllocCallbackDefault(const psMemBlock *memBlock)
    159158{
    160     static psMemId incr = 0; // "p_psMemAllocID += incr"
     159    static psMemId incr = 0; // "memAllocID += incr"
    161160
    162161    return incr;
     
    184183
    185184// notify user when this block is allocated
    186 // XXX why was this not static, and why was it p_psMemAllocID?
    187 static psMemId p_psMemAllocID = 0;
     185static psMemId memAllocID = 0;
    188186
    189187// the above callback is only called if a specific psMemId is set with this function
     
    194192    MUTEX_LOCK(&memBlockListMutex);
    195193
    196     psMemId old = p_psMemAllocID;
    197 
    198     p_psMemAllocID = id;
     194    psMemId old = memAllocID;
     195
     196    memAllocID = id;
    199197
    200198    MUTEX_UNLOCK(&memBlockListMutex);
     
    208206static psMemId memFreeCallbackDefault(const psMemBlock *memBlock)
    209207{
    210     static psMemId incr = 0; // "p_psMemFreeID += incr"
     208    static psMemId incr = 0; // "memFreeID += incr"
    211209
    212210    return incr;
     
    235233
    236234// notify user when this block is freed
    237 // XXX why was this not static?
    238 static psMemId p_psMemFreeID = 0;
     235static psMemId memFreeID = 0;
    239236
    240237// the above callback is only called if a specific psMemId is set with this function
     
    244241    MUTEX_LOCK(&memBlockListMutex);
    245242
    246     psMemId old = p_psMemFreeID;
    247 
    248     p_psMemFreeID = id;
     243    psMemId old = memFreeID;
     244
     245    memFreeID = id;
    249246
    250247    MUTEX_UNLOCK(&memBlockListMutex);
     
    286283psMemId memAllocCallbackCheckCorruption(const psMemBlock *memBlock)
    287284{
    288     static psMemId incr = 10; // "p_psMemAllocID += incr"
     285    static psMemId incr = 10; // "memAllocID += incr"
    289286
    290287    if (psMemCheckCorruption(stderr, false) > 0) {
     
    412409
    413410    // Did the user ask to be informed about this allocation?
    414     if (memBlock->id == p_psMemAllocID) {
    415         // p_psMemAllocID can only be changed while the memBlockList mutex is held
    416         p_psMemAllocID += memAllocCallback(memBlock);
     411    if (memBlock->id == memAllocID) {
     412        // memAllocID can only be changed while the memBlockList mutex is held
     413        memAllocID += memAllocCallback(memBlock);
    417414    }
    418415
     
    575572
    576573    // Did the user ask to be informed about this allocation?
    577     if (memBlock->id == p_psMemAllocID) {
    578         p_psMemAllocID += memAllocCallback(memBlock);
     574    if (memBlock->id == memAllocID) {
     575        memAllocID += memAllocCallback(memBlock);
    579576    }
    580577
     
    734731    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    735732
    736     // XXX we probably need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and
     733    // we need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and
    737734    // refCounter--;
     735    MUTEX_LOCK(&memBlockListMutex);
    738736    memBlock->refCounter++;
     737    MUTEX_UNLOCK(&memBlockListMutex);
    739738
    740739    // Did the user ask to be informed about this allocation?
     
    742741    // this lock is probably not needed: if someone changes the callback ID in a different thread,
    743742    // do we really care about really rarely getting this wrong?
    744     if (memBlock->id == p_psMemAllocID) {
     743    if (memBlock->id == memAllocID) {
    745744        MUTEX_LOCK(&memBlockListMutex);
    746         p_psMemAllocID += memAllocCallback(memBlock);
     745        memAllocID += memAllocCallback(memBlock);
    747746        MUTEX_UNLOCK(&memBlockListMutex);
    748747    }
     
    801800
    802801    // if we have multiple references, just decrement the count and return.
    803     // XXX we probably need a MUTEX_LOCK here: otherwise, two functions can race on refCounter--;
     802    // we need a MUTEX_LOCK here: otherwise, two functions can race on refCounter--;
     803    MUTEX_LOCK(&memBlockListMutex);
    804804    if (memBlock->refCounter > 1) {
    805805        memBlock->refCounter--;
    806806
    807807        // Did the user ask to be informed about this deallocation?
    808         MUTEX_LOCK(&memBlockListMutex);
    809         if (memBlock->id == p_psMemFreeID) {
    810             p_psMemFreeID += memFreeCallback(memBlock);
     808        if (memBlock->id == memFreeID) {
     809            memFreeID += memFreeCallback(memBlock);
    811810        }
    812811        MUTEX_UNLOCK(&memBlockListMutex);
    813812        return ptr;
    814813    }
     814    MUTEX_UNLOCK(&memBlockListMutex);
    815815
    816816    // we can't invoke freeFunc() while we're holding memBlockListMutex as it
     
    824824
    825825    // Did the user ask to be informed about this deallocation?
    826     if (memBlock->id == p_psMemFreeID) {
    827         p_psMemFreeID += memFreeCallback(ptr);
     826    if (memBlock->id == memFreeID) {
     827        memFreeID += memFreeCallback(ptr);
    828828    }
    829829
Note: See TracChangeset for help on using the changeset viewer.