Changeset 19128
- Timestamp:
- Aug 19, 2008, 4:00:20 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psMemory.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psMemory.c
r18826 r19128 10 10 * @author Joshua Hoblitt, University of Hawaii 11 11 * 12 * @version $Revision: 1. 99$ $Name: not supported by cvs2svn $13 * @date $Date: 2008-0 7-31 23:56:10 $12 * @version $Revision: 1.100 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2008-08-20 02:00:20 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 81 81 // p_psMemAllocID -- rarely accessed 82 82 // p_psMemFreeID -- rarely accessed 83 // lastMemBlockAllocated 84 // memid -- rarely accessby 83 // lastMemBlockAllocated 84 // memid -- rarely accessby 85 85 // "the linked list of mem blocks" 86 86 // … … 185 185 // notify user when this block is allocated 186 186 // XXX why was this not static, and why was it p_psMemAllocID? 187 static psMemId p_psMemAllocID = 0; 187 static psMemId p_psMemAllocID = 0; 188 188 189 189 // the above callback is only called if a specific psMemId is set with this function … … 327 327 } 328 328 329 // pointer to the last mem block that was allocated. 329 // pointer to the last mem block that was allocated. 330 330 // This is the root of the entire memory list 331 331 static psMemBlock *lastMemBlockAllocated = NULL; … … 341 341 psMemBlock *memBlock = malloc(sizeof(psMemBlock) + size + sizeof(void *)); 342 342 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) 344 344 MUTEX_LOCK(&memBlockListMutex); 345 345 memBlock = memExhaustedCallback(size); … … 377 377 void **bt = malloc(BACKTRACE_BUFFER_SIZE * sizeof(void *)); 378 378 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); 380 381 } 381 382 *(size_t *)&memBlock->backtraceSize = backtrace(bt, BACKTRACE_BUFFER_SIZE); … … 403 404 404 405 // 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 block407 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; 410 411 lastMemBlockAllocated = memBlock; 411 412 412 413 // Did the user ask to be informed about this allocation? 413 414 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 416 416 p_psMemAllocID += memAllocCallback(memBlock); 417 417 } … … 424 424 425 425 /* 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, 427 427 * N.b. If the block wasn't allocated by psAlloc, it will appear corrupted 428 428 */ … … 537 537 // this lock is frequently called in a given program 538 538 MUTEX_LOCK(&memBlockListMutex); 539 539 540 540 psMemBlock *nextBlock = memBlock->nextBlock; 541 541 psMemBlock *previousBlock = memBlock->previousBlock; … … 734 734 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 735 735 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--; 737 738 memBlock->refCounter++; 738 739 … … 741 742 // this lock is probably not needed: if someone changes the callback ID in a different thread, 742 743 // do we really care about really rarely getting this wrong? 743 // MUTEX_LOCK(&memBlockListMutex);744 744 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 } 750 749 751 750 return ptr; … … 807 806 808 807 // Did the user ask to be informed about this deallocation? 809 //MUTEX_LOCK(&memBlockListMutex);808 MUTEX_LOCK(&memBlockListMutex); 810 809 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); 816 813 return ptr; 817 814 } … … 828 825 // Did the user ask to be informed about this deallocation? 829 826 if (memBlock->id == p_psMemFreeID) { 830 // p_psMemFreeID += memFreeCallback(ptr); 831 memFreeCallback(ptr); 827 p_psMemFreeID += memFreeCallback(ptr); 832 828 } 833 829
Note:
See TracChangeset
for help on using the changeset viewer.
