IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 19, 2008, 4:00:20 PM (18 years ago)
Author:
Paul Price
Message:

memBlock->nextBlock wasn't being set when !lastMemBlockAllocated.
Restored incrementing of callback IDs.

File:
1 edited

Legend:

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

    r18826 r19128  
    1010*  @author Joshua Hoblitt, University of Hawaii
    1111*
    12 *  @version $Revision: 1.99 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2008-07-31 23:56:10 $
     12*  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2008-08-20 02:00:20 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    8181//      p_psMemAllocID -- rarely accessed
    8282//      p_psMemFreeID -- rarely accessed
    83 //      lastMemBlockAllocated 
    84 //      memid -- rarely accessby 
     83//      lastMemBlockAllocated
     84//      memid -- rarely accessby
    8585//      "the linked list of mem blocks"
    8686//
     
    185185// notify user when this block is allocated
    186186// XXX why was this not static, and why was it p_psMemAllocID?
    187 static psMemId p_psMemAllocID = 0;       
     187static psMemId p_psMemAllocID = 0;
    188188
    189189// the above callback is only called if a specific psMemId is set with this function
     
    327327}
    328328
    329 // pointer to the last mem block that was allocated. 
     329// pointer to the last mem block that was allocated.
    330330// This is the root of the entire memory list
    331331static psMemBlock *lastMemBlockAllocated = NULL;
     
    341341    psMemBlock *memBlock = malloc(sizeof(psMemBlock) + size + sizeof(void *));
    342342    if (memBlock == NULL) {
    343         // this lock is only occasionally called in a given program (rarely fail malloc)
     343        // this lock is only occasionally called in a given program (rarely fail malloc)
    344344        MUTEX_LOCK(&memBlockListMutex);
    345345        memBlock = memExhaustedCallback(size);
     
    377377    void **bt = malloc(BACKTRACE_BUFFER_SIZE * sizeof(void *));
    378378    if (bt == NULL) {
    379         PS_MEM_ABORT(__func__, "Failed to allocate memory for backtrace buffer: %zd bytes at %s (%s:%d)", 32 * sizeof(void *), func, file, lineno);
     379        PS_MEM_ABORT(__func__, "Failed to allocate memory for backtrace buffer: %zd bytes at %s (%s:%d)",
     380                     32 * sizeof(void *), func, file, lineno);
    380381    }
    381382    *(size_t *)&memBlock->backtraceSize = backtrace(bt, BACKTRACE_BUFFER_SIZE);
     
    403404
    404405    // insert the new block to the front of the memBlock linked-list
    405     if (lastMemBlockAllocated != NULL) {
    406         // exchange forward and backward references with the last allocated block
    407         lastMemBlockAllocated->previousBlock = memBlock;
    408         memBlock->nextBlock = lastMemBlockAllocated;
    409     }
     406    if (lastMemBlockAllocated) {
     407        // exchange forward and backward references with the last allocated block
     408        lastMemBlockAllocated->previousBlock = memBlock;
     409    }
     410    memBlock->nextBlock = lastMemBlockAllocated;
    410411    lastMemBlockAllocated = memBlock;
    411412
    412413    // Did the user ask to be informed about this allocation?
    413414    if (memBlock->id == p_psMemAllocID) {
    414         // p_psMemAllocID can only be changed while the memBlockList mutex is
    415         // held
     415        // p_psMemAllocID can only be changed while the memBlockList mutex is held
    416416        p_psMemAllocID += memAllocCallback(memBlock);
    417417    }
     
    424424
    425425/* internal routine to check the consistency of the allocated and/or free memory arena.
    426  * this is used by the user functions below (psMem{Set,Get}Deallocator, 
     426 * this is used by the user functions below (psMem{Set,Get}Deallocator,
    427427 * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted
    428428 */
     
    537537    // this lock is frequently called in a given program
    538538    MUTEX_LOCK(&memBlockListMutex);
    539    
     539
    540540    psMemBlock *nextBlock = memBlock->nextBlock;
    541541    psMemBlock *previousBlock = memBlock->previousBlock;
     
    734734    HANDLE_BAD_BLOCK(memBlock, file, lineno, func);
    735735
    736     // XXX we probably need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and refCounter--;
     736    // XXX we probably need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and
     737    // refCounter--;
    737738    memBlock->refCounter++;
    738739
     
    741742    // this lock is probably not needed: if someone changes the callback ID in a different thread,
    742743    // do we really care about really rarely getting this wrong?
    743     // MUTEX_LOCK(&memBlockListMutex);
    744744    if (memBlock->id == p_psMemAllocID) {
    745         // XXX this is seriously bogus: why are we changing this value??
    746         // p_psMemAllocID += memAllocCallback(memBlock);
    747         memAllocCallback(memBlock);
    748     }
    749     // MUTEX_UNLOCK(&memBlockListMutex);
     745        MUTEX_LOCK(&memBlockListMutex);
     746        p_psMemAllocID += memAllocCallback(memBlock);
     747        MUTEX_UNLOCK(&memBlockListMutex);
     748    }
    750749
    751750    return ptr;
     
    807806
    808807        // Did the user ask to be informed about this deallocation?
    809         // MUTEX_LOCK(&memBlockListMutex);
     808        MUTEX_LOCK(&memBlockListMutex);
    810809        if (memBlock->id == p_psMemFreeID) {
    811             // XXX why modify this?  this seems bogus
    812             // p_psMemFreeID += memFreeCallback(memBlock);
    813             memFreeCallback(memBlock);
    814         }
    815         // MUTEX_UNLOCK(&memBlockListMutex);
     810            p_psMemFreeID += memFreeCallback(memBlock);
     811        }
     812        MUTEX_UNLOCK(&memBlockListMutex);
    816813        return ptr;
    817814    }
     
    828825    // Did the user ask to be informed about this deallocation?
    829826    if (memBlock->id == p_psMemFreeID) {
    830         // p_psMemFreeID += memFreeCallback(ptr);
    831         memFreeCallback(ptr);
     827        p_psMemFreeID += memFreeCallback(ptr);
    832828    }
    833829
Note: See TracChangeset for help on using the changeset viewer.