Changeset 21346
- Timestamp:
- Feb 5, 2009, 3:05:30 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psMemory.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psMemory.c
r19128 r21346 10 10 * @author Joshua Hoblitt, University of Hawaii 11 11 * 12 * @version $Revision: 1.10 0$ $Name: not supported by cvs2svn $13 * @date $Date: 200 8-08-20 02:00:20 $12 * @version $Revision: 1.101 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2009-02-06 01:05:30 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 79 79 // memFreeCallback -- very rarely accessed 80 80 // memExhaustedCallback -- very rarely accessed 81 // p_psMemAllocID -- rarely accessed82 // p_psMemFreeID -- rarely accessed81 // memAllocID -- rarely accessed 82 // memFreeID -- rarely accessed 83 83 // lastMemBlockAllocated 84 84 // memid -- rarely accessby 85 85 // "the linked list of mem blocks" 86 86 // 87 // This is a fair am mount of stuff to protect with a single mutex but most of87 // This is a fair amount of stuff to protect with a single mutex but most of 88 88 // these items are *VERY* low contention items. The only item that should be 89 89 // 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 a90 // problem in production use of the list could be disabled as it is largely a 91 91 // debugging feature. 92 92 // 93 // XXX make the mem block list a build time option94 93 // 95 94 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER; … … 158 157 static psMemId memAllocCallbackDefault(const psMemBlock *memBlock) 159 158 { 160 static psMemId incr = 0; // " p_psMemAllocID += incr"159 static psMemId incr = 0; // "memAllocID += incr" 161 160 162 161 return incr; … … 184 183 185 184 // 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; 185 static psMemId memAllocID = 0; 188 186 189 187 // the above callback is only called if a specific psMemId is set with this function … … 194 192 MUTEX_LOCK(&memBlockListMutex); 195 193 196 psMemId old = p_psMemAllocID;197 198 p_psMemAllocID = id;194 psMemId old = memAllocID; 195 196 memAllocID = id; 199 197 200 198 MUTEX_UNLOCK(&memBlockListMutex); … … 208 206 static psMemId memFreeCallbackDefault(const psMemBlock *memBlock) 209 207 { 210 static psMemId incr = 0; // " p_psMemFreeID += incr"208 static psMemId incr = 0; // "memFreeID += incr" 211 209 212 210 return incr; … … 235 233 236 234 // notify user when this block is freed 237 // XXX why was this not static? 238 static psMemId p_psMemFreeID = 0; 235 static psMemId memFreeID = 0; 239 236 240 237 // the above callback is only called if a specific psMemId is set with this function … … 244 241 MUTEX_LOCK(&memBlockListMutex); 245 242 246 psMemId old = p_psMemFreeID;247 248 p_psMemFreeID = id;243 psMemId old = memFreeID; 244 245 memFreeID = id; 249 246 250 247 MUTEX_UNLOCK(&memBlockListMutex); … … 286 283 psMemId memAllocCallbackCheckCorruption(const psMemBlock *memBlock) 287 284 { 288 static psMemId incr = 10; // " p_psMemAllocID += incr"285 static psMemId incr = 10; // "memAllocID += incr" 289 286 290 287 if (psMemCheckCorruption(stderr, false) > 0) { … … 412 409 413 410 // 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 held416 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); 417 414 } 418 415 … … 575 572 576 573 // 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); 579 576 } 580 577 … … 734 731 HANDLE_BAD_BLOCK(memBlock, file, lineno, func); 735 732 736 // XXX we probablyneed a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and733 // we need a MUTEX_LOCK here: otherwise, two functions can race on recCounter++ and 737 734 // refCounter--; 735 MUTEX_LOCK(&memBlockListMutex); 738 736 memBlock->refCounter++; 737 MUTEX_UNLOCK(&memBlockListMutex); 739 738 740 739 // Did the user ask to be informed about this allocation? … … 742 741 // this lock is probably not needed: if someone changes the callback ID in a different thread, 743 742 // do we really care about really rarely getting this wrong? 744 if (memBlock->id == p_psMemAllocID) {743 if (memBlock->id == memAllocID) { 745 744 MUTEX_LOCK(&memBlockListMutex); 746 p_psMemAllocID += memAllocCallback(memBlock);745 memAllocID += memAllocCallback(memBlock); 747 746 MUTEX_UNLOCK(&memBlockListMutex); 748 747 } … … 801 800 802 801 // 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); 804 804 if (memBlock->refCounter > 1) { 805 805 memBlock->refCounter--; 806 806 807 807 // 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); 811 810 } 812 811 MUTEX_UNLOCK(&memBlockListMutex); 813 812 return ptr; 814 813 } 814 MUTEX_UNLOCK(&memBlockListMutex); 815 815 816 816 // we can't invoke freeFunc() while we're holding memBlockListMutex as it … … 824 824 825 825 // 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); 828 828 } 829 829
Note:
See TracChangeset
for help on using the changeset viewer.
