Changeset 1440 for trunk/psLib/src/sys/psMemory.c
- Timestamp:
- Aug 9, 2004, 1:34:58 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psMemory.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/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) {
Note:
See TracChangeset
for help on using the changeset viewer.
