Changeset 1440 for trunk/psLib/src/sysUtils
- Timestamp:
- Aug 9, 2004, 1:34:58 PM (22 years ago)
- Location:
- trunk/psLib/src/sysUtils
- Files:
-
- 4 edited
-
psMemory.c (modified) (22 diffs)
-
psMemory.h (modified) (6 diffs)
-
psTrace.c (modified) (8 diffs)
-
psTrace.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psMemory.c
r1407 r1440 9 9 * @author Robert Lupton, Princeton University 10 10 * 11 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-08-0 7 00:06:06$11 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-08-09 23:34:58 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 31 #define P_PS_LARGE_BLOCK_SIZE 65536 // size where under, we try to recycle 32 32 33 static int checkMemBlock(const psMemBlock * m, const char *funcName);34 static psMemBlock *lastMemBlockAllocated = NULL;33 static int checkMemBlock(const psMemBlock* m, const char *funcName); 34 static psMemBlock* lastMemBlockAllocated = NULL; 35 35 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER; 36 36 static pthread_mutex_t memIdMutex = PTHREAD_MUTEX_INITIALIZER; … … 44 44 45 45 // N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops) 46 static psMemBlock *recycleMemBlockList[13] = {46 static psMemBlock* recycleMemBlockList[13] = { 47 47 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL 48 48 }; 49 49 50 50 #ifdef PS_MEM_DEBUG 51 static psMemBlock *deadBlockList; // a place to put dead memBlocks in debug mode.51 static psMemBlock* deadBlockList; // a place to put dead memBlocks in debug mode. 52 52 #endif 53 53 … … 69 69 while (level >= 0 && ptr == NULL) { 70 70 while (recycleMemBlockList[level] != NULL && ptr == NULL) { 71 psMemBlock *old = recycleMemBlockList[level];71 psMemBlock* old = recycleMemBlockList[level]; 72 72 73 73 recycleMemBlockList[level] = recycleMemBlockList[level]->nextBlock; … … 97 97 } 98 98 99 static void memProblemCallbackDefault(const psMemBlock * ptr, const char *file, int lineno)99 static void memProblemCallbackDefault(const psMemBlock* ptr, const char *file, int lineno) 100 100 { 101 101 if (ptr->refCounter < 1) { … … 156 156 * isn't resignalled) 157 157 */ 158 static psMemoryId memAllocateCallbackDefault(const psMemBlock * ptr)158 static psMemoryId memAllocateCallbackDefault(const psMemBlock* ptr) 159 159 { 160 160 static psMemoryId incr = 0; // "p_psMemAllocateID += incr" … … 163 163 } 164 164 165 static psMemoryId memFreeCallbackDefault(const psMemBlock * ptr)165 static psMemoryId memFreeCallbackDefault(const psMemBlock* ptr) 166 166 { 167 167 static psMemoryId incr = 0; // "p_psMemFreeID += incr" … … 222 222 */ 223 223 224 static int checkMemBlock(const psMemBlock * m, const char *funcName)224 static int checkMemBlock(const psMemBlock* m, const char *funcName) 225 225 { 226 226 // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked, … … 257 257 pthread_mutex_lock(&memBlockListMutex); 258 258 259 for (psMemBlock * iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock) {259 for (psMemBlock* iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock) { 260 260 if (checkMemBlock(iter, __func__)) { 261 261 nbad++; … … 280 280 { 281 281 282 psMemBlock *ptr = NULL;282 psMemBlock* ptr = NULL; 283 283 284 284 // memory is of the size I want to bother recycling? … … 327 327 // increment the memory id safely. 328 328 pthread_mutex_lock(&memBlockListMutex); 329 *(psMemoryId *) & ptr->id = ++memid;329 *(psMemoryId* ) & ptr->id = ++memid; 330 330 pthread_mutex_unlock(&memBlockListMutex); 331 331 … … 363 363 return p_psAlloc(size, file, lineno); 364 364 } else { 365 psMemBlock *ptr = ((psMemBlock *) vptr) - 1;365 psMemBlock* ptr = ((psMemBlock* ) vptr) - 1; 366 366 bool isBlockLast = false; 367 367 … … 376 376 isBlockLast = (ptr == lastMemBlockAllocated); 377 377 378 ptr = (psMemBlock *) realloc(ptr, sizeof(psMemBlock) + size + sizeof(void *));378 ptr = (psMemBlock* ) realloc(ptr, sizeof(psMemBlock) + size + sizeof(void *)); 379 379 380 380 if (ptr == NULL) { … … 415 415 * Check for memory leaks. 416 416 */ 417 int psMemCheckLeaks(psMemoryId id0, psMemBlock *** arr, FILE * fd)417 int psMemCheckLeaks(psMemoryId id0, psMemBlock* ** arr, FILE * fd) 418 418 { 419 419 int nleak = 0; 420 420 int j = 0; 421 psMemBlock *topBlock = lastMemBlockAllocated;421 psMemBlock* topBlock = lastMemBlockAllocated; 422 422 423 423 pthread_mutex_lock(&memBlockListMutex); 424 424 425 for (psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock) {425 for (psMemBlock* iter = topBlock; iter != NULL; iter = iter->nextBlock) { 426 426 if ((psMemGetRefCounter(iter + 1) > 0) && (iter->id >= id0)) { 427 427 nleak++; … … 446 446 pthread_mutex_lock(&memBlockListMutex); 447 447 448 for (psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock) {448 for (psMemBlock* iter = topBlock; iter != NULL; iter = iter->nextBlock) { 449 449 if ((psMemGetRefCounter(iter + 1) > 0) && (iter->id >= id0)) { 450 450 (*arr)[j++] = iter; … … 466 466 psReferenceCount psMemGetRefCounter(void *vptr) 467 467 { 468 psMemBlock *ptr;468 psMemBlock* ptr; 469 469 unsigned int refCount; 470 470 … … 473 473 } 474 474 475 ptr = ((psMemBlock *) vptr) - 1;475 ptr = ((psMemBlock* ) vptr) - 1; 476 476 477 477 if (checkMemBlock(ptr, __func__) != 0) { … … 489 489 void *p_psMemIncrRefCounter(void *vptr, const char *file, int lineno) 490 490 { 491 psMemBlock *ptr;491 psMemBlock* ptr; 492 492 493 493 if (vptr == NULL) { … … 495 495 } 496 496 497 ptr = ((psMemBlock *) vptr) - 1;497 ptr = ((psMemBlock* ) vptr) - 1; 498 498 499 499 if (checkMemBlock(ptr, __func__)) { … … 515 515 } 516 516 517 psMemBlock *ptr = ((psMemBlock *) vptr) - 1;517 psMemBlock* ptr = ((psMemBlock* ) vptr) - 1; 518 518 519 519 if (checkMemBlock(ptr, __func__) != 0) { … … 607 607 } 608 608 609 psMemBlock *ptr = ((psMemBlock *) vptr) - 1;609 psMemBlock* ptr = ((psMemBlock* ) vptr) - 1; 610 610 611 611 if (checkMemBlock(ptr, __func__) != 0) { … … 622 622 } 623 623 624 psMemBlock *ptr = ((psMemBlock *) vptr) - 1;624 psMemBlock* ptr = ((psMemBlock* ) vptr) - 1; 625 625 626 626 if (checkMemBlock(ptr, __func__) != 0) { -
trunk/psLib/src/sysUtils/psMemory.h
r1426 r1440 15 15 * @ingroup MemoryManagement 16 16 * 17 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $18 * @date $Date: 2004-08-09 2 2:44:25$17 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2004-08-09 23:34:58 $ 19 19 * 20 20 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 64 64 { 65 65 const void *startblock; ///< initialised to p_psMEMMAGIC 66 struct psMemBlock *previousBlock; ///< previous block in allocation list67 struct psMemBlock *nextBlock; ///< next block allocation list66 struct psMemBlock* previousBlock; ///< previous block in allocation list 67 struct psMemBlock* nextBlock; ///< next block allocation list 68 68 psFreeFcn freeFcn; ///< deallocator. If NULL, use generic deallocation. 69 69 size_t userMemorySize; ///< the size of the user-portion of the memory block … … 82 82 * @ingroup memCallback 83 83 */ 84 typedef psMemoryId(*psMemAllocateCallback) (const psMemBlock * ptr ///< the psMemBlock just allocated84 typedef psMemoryId(*psMemAllocateCallback) (const psMemBlock* ptr ///< the psMemBlock just allocated 85 85 ); 86 86 … … 90 90 * @ingroup memCallback 91 91 */ 92 typedef psMemoryId(*psMemFreeCallback) (const psMemBlock * ptr ///< the psMemBlock being freed92 typedef psMemoryId(*psMemFreeCallback) (const psMemBlock* ptr ///< the psMemBlock being freed 93 93 ); 94 94 … … 100 100 * @ingroup memCallback 101 101 */ 102 typedef void (*psMemProblemCallback) (const psMemBlock * ptr, ///< the pointer to the problematic memory102 typedef void (*psMemProblemCallback) (const psMemBlock* ptr, ///< the pointer to the problematic memory 103 103 // block. 104 104 const char *file, ///< the file in which the problem originated … … 195 195 */ 196 196 int psMemCheckLeaks(psMemoryId id0, ///< don't list blocks with id < id0 197 psMemBlock *** arr, ///< pointer to array of pointers to leaked blocks, or NULL197 psMemBlock* ** arr, ///< pointer to array of pointers to leaked blocks, or NULL 198 198 FILE * fd ///< print list of leaks to fd (or NULL) 199 199 ); -
trunk/psLib/src/sysUtils/psTrace.c
r1407 r1440 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-0 7 00:06:06$12 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-09 23:34:58 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 45 45 # include "psError.h" 46 46 47 static p_psComponent *p_psCroot = NULL; // The root of the trace component47 static p_psComponent* p_psCroot = NULL; // The root of the trace component 48 48 static FILE *p_psTraceFP = NULL; // File destination for messages. 49 49 50 static void componentFree(p_psComponent * comp);51 static p_psComponent *componentAlloc(const char *name, int level);50 static void componentFree(p_psComponent* comp); 51 static p_psComponent* componentAlloc(const char *name, int level); 52 52 53 53 /***************************************************************************** 54 54 componentAlloc(): allocate memory for a new node, and initialize members. 55 55 *****************************************************************************/ 56 static p_psComponent *componentAlloc(const char *name, int level)57 { 58 p_psComponent *comp = psAlloc(sizeof(p_psComponent));56 static p_psComponent* componentAlloc(const char *name, int level) 57 { 58 p_psComponent* comp = psAlloc(sizeof(p_psComponent)); 59 59 60 60 p_psMemSetDeallocator(comp, (psFreeFcn) componentFree); … … 70 70 nodes as well. 71 71 *****************************************************************************/ 72 static void componentFree(p_psComponent * comp)72 static void componentFree(p_psComponent* comp) 73 73 { 74 74 if (comp == NULL) { … … 99 99 Set all trace levels to zero. 100 100 *****************************************************************************/ 101 void p_psTraceReset(p_psComponent * currentNode)101 void p_psTraceReset(p_psComponent* currentNode) 102 102 { 103 103 int i = 0; … … 147 147 char *pname = name; 148 148 char *firstComponent = NULL; // first component of name 149 p_psComponent *currentNode = p_psCroot;149 p_psComponent* currentNode = p_psCroot; 150 150 int nodeExists = 0; 151 151 … … 182 182 if (nodeExists == 0) { 183 183 currentNode->subcomp = psRealloc(currentNode->subcomp, 184 (currentNode->n + 1) * sizeof(p_psComponent *));184 (currentNode->n + 1) * sizeof(p_psComponent* )); 185 185 currentNode->n = (currentNode->n) + 1; 186 186 … … 234 234 char *pname = name; 235 235 char *firstComponent = NULL; // first component of name 236 p_psComponent *currentNode = p_psCroot;236 p_psComponent* currentNode = p_psCroot; 237 237 int i = 0; 238 238 … … 303 303 null 304 304 *****************************************************************************/ 305 static void doPrintTraceLevels(const p_psComponent * comp, int depth)305 static void doPrintTraceLevels(const p_psComponent* comp, int depth) 306 306 { 307 307 int i = 0; -
trunk/psLib/src/sysUtils/psTrace.h
r1426 r1440 10 10 * @author George Gusciora, MHPCC 11 11 * 12 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-09 2 2:44:25$12 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-09 23:34:58 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 53 53 int level; // trace level for this component 54 54 int n; // number of subcomponents 55 struct p_psComponent **subcomp; // next level of subcomponents55 struct p_psComponent* *subcomp; // next level of subcomponents 56 56 } 57 57 p_psComponent;
Note:
See TracChangeset
for help on using the changeset viewer.
