Changeset 2204 for trunk/psLib/src/sysUtils
- Timestamp:
- Oct 26, 2004, 2:57:34 PM (22 years ago)
- Location:
- trunk/psLib/src/sysUtils
- Files:
-
- 13 edited
-
psError.c (modified) (6 diffs)
-
psError.h (modified) (3 diffs)
-
psErrorCodes.c (modified) (7 diffs)
-
psErrorCodes.h (modified) (3 diffs)
-
psLogMsg.c (modified) (10 diffs)
-
psLogMsg.h (modified) (6 diffs)
-
psMemory.c (modified) (28 diffs)
-
psMemory.h (modified) (19 diffs)
-
psString.c (modified) (2 diffs)
-
psString.h (modified) (3 diffs)
-
psTrace.c (modified) (14 diffs)
-
psTrace.h (modified) (4 diffs)
-
psType.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psError.c
r1905 r2204 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $13 * @date $Date: 2004- 09-27 20:38:02$12 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-10-27 00:57:31 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 #define MAX_ERROR_STACK_SIZE 64 27 27 static psErr* errorStack[MAX_ERROR_STACK_SIZE]; 28 static unsigned interrorStackSize = 0;28 static psU32 errorStackSize = 0; 29 29 pthread_mutex_t lockErrorStack = PTHREAD_MUTEX_INITIALIZER; 30 30 … … 84 84 { 85 85 pthread_mutex_lock(&lockErrorStack); 86 for ( intlcv=0;lcv<errorStackSize;lcv++) {86 for (psS32 lcv=0;lcv<errorStackSize;lcv++) { 87 87 p_psMemSetPersistent(errorStack[lcv]->msg,false); 88 88 p_psMemSetPersistent(errorStack[lcv]->name,false); … … 94 94 } 95 95 96 psErrorCode psErrorMsg(const char *name, psErrorCode code, bool new, const char* fmt, ...)96 psErrorCode psErrorMsg(const char *name, psErrorCode code, psBool new, const char* fmt, ...) 97 97 { 98 98 char errMsg[1024]; … … 131 131 } 132 132 133 psErr* psErrorGet( intwhich)133 psErr* psErrorGet(psS32 which) 134 134 { 135 135 psErr* result; … … 180 180 vfprintf(fd,fmt,va); 181 181 182 for ( intlcv=0;lcv<errorStackSize;lcv++) {182 for (psS32 lcv=0;lcv<errorStackSize;lcv++) { 183 183 if(errorStack[lcv]->code >= PS_ERR_BASE) { 184 184 fprintf(fd," -> %s: %s\n %s\n", -
trunk/psLib/src/sysUtils/psError.h
r1869 r2204 12 12 * @author Eric Van Alst, MHPCC 13 13 * 14 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-23 22:18:13$14 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-10-27 00:57:31 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 51 51 */ 52 52 psErr* psErrorGet( 53 intwhich ///< position in the error stack. 0 is last error on stack.53 psS32 which ///< position in the error stack. 0 is last error on stack. 54 54 ); 55 55 … … 121 121 const char *name, ///< Name of error in the form aaa.bbb.ccc 122 122 psErrorCode code, ///< Error class code 123 bool new, ///< true if error originates at this location123 psBool new, ///< true if error originates at this location 124 124 const char* fmt, ///< printf style formatting statement defining error message 125 125 ... -
trunk/psLib/src/sysUtils/psErrorCodes.c
r2129 r2204 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10- 14 21:14:58$9 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-27 00:57:31 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 59 59 // first, search the static error codes 60 60 61 intn = 0;61 psS32 n = 0; 62 62 while(staticErrorCodes[n].code != PS_ERR_N_ERR_CLASSES && 63 63 staticErrorCodes[n].code != code) { … … 88 88 static void freeErrorDescription(psErrorDescription* err) 89 89 { 90 psFree(( void*)err->description);90 psFree((psPtr)err->description); 91 91 } 92 92 … … 125 125 126 126 void psErrorRegister(const psErrorDescription* errors, 127 intnerror)127 psS32 nerror) 128 128 { 129 129 if (nerror < 1) { … … 143 143 } 144 144 145 for ( inti=0;i<nerror;i++) {145 for (psS32 i=0;i<nerror;i++) { 146 146 psErrorDescription* err = psErrorDescriptionAlloc( 147 147 errors[i].code, errors[i].description); 148 148 p_psMemSetPersistent(err,true); 149 p_psMemSetPersistent(( void*)err->description,true);149 p_psMemSetPersistent((psPtr)err->description,true); 150 150 if (! psListAdd(dynamicErrorCodes, 151 151 PS_LIST_HEAD, … … 162 162 } 163 163 164 bool p_psErrorUnregister(psErrorCode code)164 psBool p_psErrorUnregister(psErrorCode code) 165 165 { 166 166 // Check input argument is non-negative … … 179 179 } 180 180 181 return psListRemove(dynamicErrorCodes,PS_LIST_UNKNOWN,( void*)desc);181 return psListRemove(dynamicErrorCodes,PS_LIST_UNKNOWN,(psPtr)desc); 182 182 } -
trunk/psLib/src/sysUtils/psErrorCodes.h
r2129 r2204 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-10- 14 21:14:58$9 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-10-27 00:57:31 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 15 #ifndef PS_ERROR_CODES_H 16 16 #define PS_ERROR_CODES_H 17 18 #include "psType.h" 17 19 18 20 /* N.B., lines between '//~Start' and '//~End' are automatic generated from … … 93 95 void psErrorRegister( 94 96 const psErrorDescription* errors, ///< Array of error codes to register 95 intnerror ///< number of errors in input array97 psS32 nerror ///< number of errors in input array 96 98 ); 97 99 98 100 /** Clears error codes registered via psErrorRegister. 99 101 * 100 * @return bool TRUE if given errorcode was removed, otherwise FALSE.102 * @return psBool TRUE if given errorcode was removed, otherwise FALSE. 101 103 */ 102 bool p_psErrorUnregister(104 psBool p_psErrorUnregister( 103 105 psErrorCode code ///< the error code to find and remove 104 106 ); -
trunk/psLib/src/sysUtils/psLogMsg.c
r1807 r2204 11 11 * @author George Gusciora, MHPCC 12 12 * 13 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $14 * @date $Date: 2004- 09-14 20:01:52$13 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-27 00:57:31 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 /***************************************************************************** 20 20 NOTES: currently, the prototype code has the following global variables: 21 static intp_psGlobalLogDest;22 static intp_psGlobalLogLevel;23 static intp_psLogTime;24 static intp_psLogHost;25 static intp_psLogLevel;26 static intp_psLogName;27 static intp_psLogMsg;21 static psS32 p_psGlobalLogDest; 22 static psS32 p_psGlobalLogLevel; 23 static psS32 p_psLogTime; 24 static psS32 p_psLogHost; 25 static psS32 p_psLogLevel; 26 static psS32 p_psLogName; 27 static psS32 p_psLogMsg; 28 28 *****************************************************************************/ 29 29 #include <limits.h> … … 34 34 #include <time.h> 35 35 #include <unistd.h> 36 #include <stdbool.h>37 36 38 37 #include "psLogMsg.h" … … 49 48 50 49 static FILE *logDest = (FILE *) 1; // flag to initialize to stderr before using. 51 static intglobalLogLevel = PS_LOG_INFO; // log all messages at this or above52 static bool logTime = true; // Flag to include time info53 static bool logHost = true; // Flag to include host info54 static bool logLevel = true; // Flag to include level info55 static bool logName = true; // Flag to include name info56 static bool logMsg = true; // Flag to include message info50 static psS32 globalLogLevel = PS_LOG_INFO; // log all messages at this or above 51 static psBool logTime = true; // Flag to include time info 52 static psBool logHost = true; // Flag to include host info 53 static psBool logLevel = true; // Flag to include level info 54 static psBool logName = true; // Flag to include name info 55 static psBool logMsg = true; // Flag to include message info 57 56 58 57 /***************************************************************************** 59 58 psLogSetLevel(): Set the current log level and return old level. 60 59 Input: 61 level ( int): the new log level.60 level (psS32): the new log level. 62 61 Output: 63 62 none … … 65 64 The old log level. 66 65 *****************************************************************************/ 67 int psLogSetLevel(intlevel)66 psS32 psLogSetLevel(psS32 level) 68 67 { 69 68 // Save old global log level for changing it. 70 intoldLevel = globalLogLevel;69 psS32 oldLevel = globalLogLevel; 71 70 72 71 if ((level < MIN_LOG_LEVEL) || (level > MAX_LOG_LEVEL)) { … … 86 85 87 86 Input: 88 dest ( int): the new log destination87 dest (psS32): the new log destination 89 88 Output: 90 89 None. … … 92 91 An integer specifying the old log destination. 93 92 *****************************************************************************/ 94 bool psLogSetDestination(const char *dest)93 psBool psLogSetDestination(const char *dest) 95 94 { 96 95 char protocol[5]; … … 245 244 NULL. 246 245 *****************************************************************************/ 247 void psLogMsgV(const char *name, intlevel, const char *fmt, va_list ap)248 { 249 static intfirst = 1; // Flag for calling gethostname()246 void psLogMsgV(const char *name, psS32 level, const char *fmt, va_list ap) 247 { 248 static psS32 first = 1; // Flag for calling gethostname() 250 249 static char hostname[HOST_NAME_MAX + 1]; 251 250 … … 254 253 char head[MAX_LOG_LINE_LENGTH + 2]; // the added two are for the ending | and \0 255 254 char *head_ptr = head; // where we've got to in head 256 intmaxLength = MAX_LOG_LINE_LENGTH;255 psS32 maxLength = MAX_LOG_LINE_LENGTH; 257 256 time_t clock = time(NULL); // The current time. 258 257 struct tm *utc = gmtime(&clock); // The current gm time. … … 375 374 NULL 376 375 *****************************************************************************/ 377 void psLogMsg(const char *name, intlevel, const char *fmt, ...)376 void psLogMsg(const char *name, psS32 level, const char *fmt, ...) 378 377 { 379 378 va_list ap; -
trunk/psLib/src/sysUtils/psLogMsg.h
r1807 r2204 11 11 * @author George Gusciora, MHPCC 12 12 * 13 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $14 * @date $Date: 2004- 09-14 20:01:52$13 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-27 00:57:31 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #define PS_LOG_MSG_H 20 20 #include <stdarg.h> 21 #include <stdbool.h> 21 22 #include "psType.h" 22 23 23 24 /** @addtogroup LogTrace … … 31 32 * argument which can specify more general log destinations. 32 33 * 33 * @return inttrue if set successfully, otherwise false.34 * @return psS32 true if set successfully, otherwise false. 34 35 */ 35 bool psLogSetDestination(36 psBool psLogSetDestination( 36 37 const char *dest ///< Specifies where to send messages. 37 38 ); … … 43 44 * be displayed. 44 45 * 45 * @return intold logging level46 * @return psS32 old logging level 46 47 */ 47 intpsLogSetLevel(48 intlevel ///< Specifies the system log level48 psS32 psLogSetLevel( 49 psS32 level ///< Specifies the system log level 49 50 ); 50 51 … … 68 69 void psLogMsg( 69 70 const char *name, ///< name of the log source 70 intmyLevel, ///< severity level of this log message71 psS32 myLevel, ///< severity level of this log message 71 72 const char *fmt, ///< printf-style format command 72 73 ... … … 79 80 void psLogMsgV( 80 81 const char *name, ///< name of the log source 81 intmyLevel, ///< severity level of this log message82 psS32 myLevel, ///< severity level of this log message 82 83 const char *fmt, ///< printf-style format command 83 84 va_list ap ///< varargs argument list -
trunk/psLib/src/sysUtils/psMemory.c
r1840 r2204 8 8 * @author Robert Lupton, Princeton University 9 9 * 10 * @version $Revision: 1.4 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2004- 09-21 22:30:19$10 * @version $Revision: 1.42 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-10-27 00:57:31 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include <stdlib.h> 19 19 #include <stdio.h> 20 #include <stdbool.h>21 20 #include <stdint.h> 22 21 … … 28 27 #include "psSysUtilsErrors.h" 29 28 30 #define P_PS_MEMMAGIC ( void *)0xdeadbeef // Magic number in psMemBlock header29 #define P_PS_MEMMAGIC (psPtr )0xdeadbeef // Magic number in psMemBlock header 31 30 32 31 #define P_PS_LARGE_BLOCK_SIZE 65536 // size where under, we try to recycle 33 32 34 static intcheckMemBlock(const psMemBlock* m, const char *funcName);33 static psS32 checkMemBlock(const psMemBlock* m, const char *funcName); 35 34 static psMemBlock* lastMemBlockAllocated = NULL; 36 35 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER; … … 39 38 static pthread_mutex_t recycleMemBlockListMutex = PTHREAD_MUTEX_INITIALIZER; 40 39 41 static intrecycleBins = 13;42 static intrecycleBinSize[14] = {43 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE44 };40 static psS32 recycleBins = 13; 41 static psS32 recycleBinSize[14] = { 42 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE 43 }; 45 44 46 45 // N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops) … … 61 60 * Default memExhausted callback. 62 61 */ 63 static void *memExhaustedCallbackDefault(size_t size)64 { 65 void *ptr = NULL;62 static psPtr memExhaustedCallbackDefault(size_t size) 63 { 64 psPtr ptr = NULL; 66 65 67 66 pthread_mutex_lock(&recycleMemBlockListMutex); 68 intlevel = recycleBins - 1;67 psS32 level = recycleBins - 1; 69 68 70 69 while (level >= 0 && ptr == NULL) { … … 98 97 } 99 98 100 static void memProblemCallbackDefault(const psMemBlock* ptr, const char *file, intlineno)99 static void memProblemCallbackDefault(const psMemBlock* ptr, const char *file, psS32 lineno) 101 100 { 102 101 if (ptr->refCounter < 1) { … … 223 222 */ 224 223 225 static intcheckMemBlock(const psMemBlock* m, const char *funcName)224 static psS32 checkMemBlock(const psMemBlock* m, const char *funcName) 226 225 { 227 226 // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked, … … 248 247 return 1; 249 248 } 250 if (*( void **)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {249 if (*(psPtr *)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) { 251 250 psErrorMsg(PS_ERRORNAME_DOMAIN "checkMemBlock", true, PS_ERR_MEMORY_CORRUPTION, 252 251 PS_ERRORTEXT_psMemory_OVERFLOW, … … 258 257 } 259 258 260 int psMemCheckCorruption(bool abort_on_error)261 { 262 intnbad = 0; // number of bad blocks263 bool failure = false;259 psS32 psMemCheckCorruption(psBool abort_on_error) 260 { 261 psS32 nbad = 0; // number of bad blocks 262 psBool failure = false; 264 263 265 264 // get exclusive access to the memBlock list to avoid it changing on us while we use it. … … 289 288 } 290 289 291 void *p_psAlloc(size_t size, const char *file, intlineno)290 psPtr p_psAlloc(size_t size, const char *file, psS32 lineno) 292 291 { 293 292 … … 297 296 if (size < P_PS_LARGE_BLOCK_SIZE) { 298 297 // find the bin we need. 299 intlevel = 0;298 psS32 level = 0; 300 299 301 300 while (size > recycleBinSize[level]) { … … 323 322 324 323 if (ptr == NULL) { 325 ptr = malloc(sizeof(psMemBlock) + size + sizeof( void *));324 ptr = malloc(sizeof(psMemBlock) + size + sizeof(psPtr )); 326 325 327 326 if (ptr == NULL) { … … 332 331 } 333 332 334 ptr->startblock = P_PS_MEMMAGIC;335 ptr->endblock = P_PS_MEMMAGIC;333 *(psPtr*)&ptr->startblock = P_PS_MEMMAGIC; 334 *(psPtr*)&ptr->endblock = P_PS_MEMMAGIC; 336 335 ptr->userMemorySize = size; 337 336 pthread_mutex_init(&ptr->refCounterMutex, NULL); … … 345 344 ptr->freeFcn = NULL; 346 345 ptr->persistent = false; 347 *( unsigned int*)&ptr->lineno = lineno;348 *( void **)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;346 *(psU32 *)&ptr->lineno = lineno; 347 *(psPtr *)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC; 349 348 ptr->previousBlock = NULL; 350 349 … … 371 370 } 372 371 373 void *p_psRealloc(void *vptr, size_t size, const char *file, intlineno)372 psPtr p_psRealloc(psPtr vptr, size_t size, const char *file, psS32 lineno) 374 373 { 375 374 if (vptr == NULL) { … … 377 376 } else { 378 377 psMemBlock* ptr = ((psMemBlock* ) vptr) - 1; 379 bool isBlockLast = false;378 psBool isBlockLast = false; 380 379 381 380 if (checkMemBlock(ptr, __func__) != 0) { … … 389 388 isBlockLast = (ptr == lastMemBlockAllocated); 390 389 391 ptr = (psMemBlock* ) realloc(ptr, sizeof(psMemBlock) + size + sizeof( void *));390 ptr = (psMemBlock* ) realloc(ptr, sizeof(psMemBlock) + size + sizeof(psPtr )); 392 391 393 392 if (ptr == NULL) { … … 399 398 400 399 ptr->userMemorySize = size; 401 *( void **)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC;400 *(psPtr *)((int8_t *) (ptr + 1) + size) = P_PS_MEMMAGIC; 402 401 403 402 if (isBlockLast) { … … 423 422 } 424 423 425 void p_psFree( void *vptr, const char *file, intlineno)424 void p_psFree(psPtr vptr, const char *file, psS32 lineno) 426 425 { 427 426 if (vptr == NULL) { … … 444 443 * Check for memory leaks. 445 444 */ 446 intpsMemCheckLeaks(psMemoryId id0, psMemBlock* ** arr, FILE * fd)447 { 448 intnleak = 0;449 intj = 0;445 psS32 psMemCheckLeaks(psMemoryId id0, psMemBlock* ** arr, FILE * fd) 446 { 447 psS32 nleak = 0; 448 psS32 j = 0; 450 449 psMemBlock* topBlock = lastMemBlockAllocated; 451 450 … … 499 498 */ 500 499 // return refCounter 501 psReferenceCount psMemGetRefCounter( void *vptr)500 psReferenceCount psMemGetRefCounter(psPtr vptr) 502 501 { 503 502 psMemBlock* ptr; 504 unsigned intrefCount;503 psU32 refCount; 505 504 506 505 if (vptr == NULL) { … … 522 521 523 522 // increment and return refCounter 524 void *p_psMemIncrRefCounter(void *vptr, const char *file, intlineno)523 psPtr p_psMemIncrRefCounter(psPtr vptr, const char *file, psS32 lineno) 525 524 { 526 525 psMemBlock* ptr; … … 544 543 545 544 // decrement and return refCounter 546 void *p_psMemDecrRefCounter(void *vptr, const char *file, intlineno)545 psPtr p_psMemDecrRefCounter(psPtr vptr, const char *file, psS32 lineno) 547 546 { 548 547 if (vptr == NULL) { … … 593 592 if (ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE) { 594 593 595 intlevel = 1;594 psS32 level = 1; 596 595 597 596 while (ptr->userMemorySize >= recycleBinSize[level]) { … … 635 634 } 636 635 637 void p_psMemSetDeallocator( void *vptr, psFreeFcn freeFcn)636 void p_psMemSetDeallocator(psPtr vptr, psFreeFcn freeFcn) 638 637 { 639 638 if (vptr == NULL) { … … 650 649 651 650 } 652 psFreeFcn p_psMemGetDeallocator( void *vptr)651 psFreeFcn p_psMemGetDeallocator(psPtr vptr) 653 652 { 654 653 if (vptr == NULL) { … … 665 664 } 666 665 667 bool p_psMemGetPersistent(void *vptr)666 psBool p_psMemGetPersistent(psPtr vptr) 668 667 { 669 668 if (vptr == NULL) { … … 680 679 } 681 680 682 void p_psMemSetPersistent( void *vptr,bool value)681 void p_psMemSetPersistent(psPtr vptr,psBool value) 683 682 { 684 683 if (vptr == NULL) { -
trunk/psLib/src/sysUtils/psMemory.h
r1810 r2204 12 12 * @ingroup MemoryManagement 13 13 * 14 * @version $Revision: 1.3 0$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-14 23:48:25$14 * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-10-27 00:57:31 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 23 23 #include <stdio.h> // needed for FILE 24 #include <stdbool.h>25 24 #include <pthread.h> // we need a mutex to make this stuff thread safe. 25 26 #include "psType.h" 26 27 27 28 /** @addtogroup MemoryManagement … … 48 49 49 50 /// typedef for memory identification numbers. Guaranteed to be some variety of integer. 50 typedef unsigned longpsMemoryId;51 typedef psU64 psMemoryId; 51 52 52 53 /// typedef for a memory block's reference count. Guaranteed to be some variety of integer. 53 typedef unsigned longpsReferenceCount;54 typedef psU64 psReferenceCount; 54 55 55 56 /// typedef for deallocator. 56 typedef void (*psFreeFcn) ( void *ptr);57 typedef void (*psFreeFcn) (psPtr ptr); 57 58 58 59 /** Book-keeping data for storage allocator. … … 63 64 typedef struct psMemBlock 64 65 { 65 const void *startblock; ///< initialised to p_psMEMMAGIC66 const psPtr startblock; ///< initialised to p_psMEMMAGIC 66 67 struct psMemBlock* previousBlock; ///< previous block in allocation list 67 68 struct psMemBlock* nextBlock; ///< next block allocation list … … 70 71 const psMemoryId id; ///< a unique ID for this allocation 71 72 const char *file; ///< set from __FILE__ in e.g. p_psAlloc 72 const intlineno; ///< set from __LINE__ in e.g. p_psAlloc73 const psS32 lineno; ///< set from __LINE__ in e.g. p_psAlloc 73 74 pthread_mutex_t refCounterMutex; ///< mutex to ensure exclusive access to reference counter 74 75 psReferenceCount refCounter; ///< how many times pointer is referenced 75 bool persistent; ///< marks if this non-user persistent data like error stack, etc.76 const void *endblock; ///< initialised to p_psMEMMAGIC76 psBool persistent; ///< marks if this non-user persistent data like error stack, etc. 77 const psPtr endblock; ///< initialised to p_psMEMMAGIC 77 78 } 78 79 psMemBlock; … … 106 107 const psMemBlock* ptr, ///< the pointer to the problematic memory block. 107 108 const char *file, ///< the file in which the problem originated 108 intlineno ///< the line number in which the problem originated109 psS32 lineno ///< the line number in which the problem originated 109 110 ); 110 111 111 112 /** prototype of a callback function used when memory runs out 112 113 * 113 * @return void*pointer to requested buffer of the size size_t, or NULL if memory could not114 * @return psPtr pointer to requested buffer of the size size_t, or NULL if memory could not 114 115 * be found. 115 116 * … … 117 118 * @ingroup memCallback 118 119 */ 119 typedef void *(*psMemExhaustedCallback) (120 typedef psPtr (*psMemExhaustedCallback) ( 120 121 size_t size ///< the size of buffer required 121 122 ); … … 123 124 /** Memory allocation. This operates much like malloc(), but is guaranteed to return a non-NULL value. 124 125 * 125 * @return void*pointer to the allocated buffer. This will not be NULL.126 * @return psPtr pointer to the allocated buffer. This will not be NULL. 126 127 * @see psFree 127 128 */ 128 129 #ifdef DOXYGEN 129 void *psAlloc(size_t size ///< Size required130 psPtr psAlloc(size_t size ///< Size required 130 131 ); 131 132 #else 132 133 133 void *p_psAlloc(size_t size, ///< Size required134 psPtr p_psAlloc(size_t size, ///< Size required 134 135 const char *file, ///< File of call 135 intlineno ///< Line number of call136 psS32 lineno ///< Line number of call 136 137 ); 137 138 … … 148 149 */ 149 150 void p_psMemSetDeallocator( 150 void *ptr, ///< the memory block to operate on151 psPtr ptr, ///< the memory block to operate on 151 152 psFreeFcn freeFcn ///< the function to be executed at deallocation 152 153 ); … … 162 163 */ 163 164 psFreeFcn p_psMemGetDeallocator( 164 void *ptr ///< the memory block165 psPtr ptr ///< the memory block 165 166 ); 166 167 … … 176 177 */ 177 178 void p_psMemSetPersistent( 178 void *ptr, ///< the memory block to operate on179 bool value ///< true if memory is persistent, otherwise false179 psPtr ptr, ///< the memory block to operate on 180 psBool value ///< true if memory is persistent, otherwise false 180 181 ); 181 182 … … 187 188 * Memory marked as persistent is excluded from memory leak checks. 188 189 * 189 * @return bool true if memory is marked persistent, otherwise false.190 */ 191 bool p_psMemGetPersistent(192 void *ptr ///< the memory block to check.190 * @return psBool true if memory is marked persistent, otherwise false. 191 */ 192 psBool p_psMemGetPersistent( 193 psPtr ptr ///< the memory block to check. 193 194 ); 194 195 … … 196 197 /** Memory re-allocation. This operates much like realloc(), but is guaranteed to return a non-NULL value. 197 198 * 198 * @return void*pointer to resized buffer. This will not be NULL.199 * @return psPtr pointer to resized buffer. This will not be NULL. 199 200 * @see psAlloc, psFree 200 201 */ 201 202 #ifdef DOXYGEN 202 void *psRealloc(203 void *ptr ///< Pointer to re-allocate203 psPtr psRealloc( 204 psPtr ptr ///< Pointer to re-allocate 204 205 size_t size, ///< Size required 205 206 ); 206 207 #else 207 208 208 void *p_psRealloc(209 void *ptr, ///< Pointer to re-allocate209 psPtr p_psRealloc( 210 psPtr ptr, ///< Pointer to re-allocate 210 211 size_t size, ///< Size required 211 212 const char *file, ///< File of call 212 intlineno ///< Line number of call213 psS32 lineno ///< Line number of call 213 214 ); 214 215 … … 224 225 #ifdef DOXYGEN 225 226 void psFree( 226 void *ptr, ///< Pointer to free, if NULL, function returns immediately.227 psPtr ptr, ///< Pointer to free, if NULL, function returns immediately. 227 228 ); 228 229 #else 229 230 230 231 void p_psFree( 231 void *ptr, ///< Pointer to free232 psPtr ptr, ///< Pointer to free 232 233 const char *file, ///< File of call 233 intlineno ///< Line number of call234 psS32 lineno ///< Line number of call 234 235 ); 235 236 … … 248 249 * If memory leaks are found, the Memory Problem callback will be called as well. 249 250 * 250 * return intnumber of memory blocks found as 'leaks', i.e., the number of currently allocated memory251 * return psS32 number of memory blocks found as 'leaks', i.e., the number of currently allocated memory 251 252 * blocks above id0 that have not been freed. 252 253 * @see psAlloc, psFree, psgetMemId, psMemProblemCallbackSet 253 254 * @ingroup memTracing 254 255 */ 255 intpsMemCheckLeaks(256 psS32 psMemCheckLeaks( 256 257 psMemoryId id0, ///< don't list blocks with id < id0 257 258 psMemBlock* ** arr, ///< pointer to array of pointers to leaked blocks, or NULL … … 264 265 * @ingroup memTracing 265 266 */ 266 intpsMemCheckCorruption(267 bool abort_on_error ///< Abort on detecting corruption?267 psS32 psMemCheckCorruption( 268 psBool abort_on_error ///< Abort on detecting corruption? 268 269 ); 269 270 … … 273 274 */ 274 275 psReferenceCount psMemGetRefCounter( 275 void *vptr ///< Pointer to get refCounter for276 psPtr vptr ///< Pointer to get refCounter for 276 277 ); 277 278 … … 281 282 */ 282 283 #ifdef DOXYGEN 283 void *psMemIncrRefCounter(284 void *vptr ///< Pointer to increment refCounter, and return285 ); 286 #else 287 288 void *p_psMemIncrRefCounter(289 void *vptr, ///< Pointer to increment refCounter, and return284 psPtr psMemIncrRefCounter( 285 psPtr vptr ///< Pointer to increment refCounter, and return 286 ); 287 #else 288 289 psPtr p_psMemIncrRefCounter( 290 psPtr vptr, ///< Pointer to increment refCounter, and return 290 291 const char *file, ///< File of call 291 intlineno ///< Line number of call292 psS32 lineno ///< Line number of call 292 293 ); 293 294 … … 299 300 * @ingroup memRefCount 300 301 * 301 * @return void*the pointer deremented in refCount, or NULL if pointer is302 * @return psPtr the pointer deremented in refCount, or NULL if pointer is 302 303 * fully dereferenced. 303 304 */ 304 305 #ifdef DOXYGEN 305 void*psMemDecrRefCounter(306 void*vptr ///< Pointer to decrement refCounter, and return307 ); 308 #else 309 310 void *p_psMemDecrRefCounter(311 void *vptr, ///< Pointer to decrement refCounter, and return306 psPtr psMemDecrRefCounter( 307 psPtr vptr ///< Pointer to decrement refCounter, and return 308 ); 309 #else 310 311 psPtr p_psMemDecrRefCounter( 312 psPtr vptr, ///< Pointer to decrement refCounter, and return 312 313 const char *file, ///< File of call 313 intlineno ///< Line number of call314 psS32 lineno ///< Line number of call 314 315 ); 315 316 -
trunk/psLib/src/sysUtils/psString.c
r1969 r2204 9 9 * @author Eric Van Alst, MHPCC 10 10 * 11 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10- 06 01:05:41 $11 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-27 00:57:31 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 31 } 32 32 33 char *psStringNCopy(const char *str, intnChar)33 char *psStringNCopy(const char *str, psS32 nChar) 34 34 { 35 35 char *returnValue = NULL; -
trunk/psLib/src/sysUtils/psString.h
r1448 r2204 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2004- 08-10 01:55:34$12 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-10-27 00:57:31 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #define PS_STRING_H 20 20 21 #include "psType.h" 21 22 22 23 /** This macro will convert the argument to a quoted string */ … … 62 63 /**< Input string of characters to copy */ 63 64 64 intnChar65 psS32 nChar 65 66 /**< Number of bytes to allocate for string copy */ 66 67 ); -
trunk/psLib/src/sysUtils/psTrace.c
r1834 r2204 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $12 * @date $Date: 2004- 09-20 22:03:35$11 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-27 00:57:31 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 35 35 PS_DEFAULT_TRACE_LEVEL: This should only be used when adding the 36 intermediate components of a longname. Ie. the "B" in .A.B.C36 intermediate components of a psS64 name. Ie. the "B" in .A.B.C 37 37 38 38 *****************************************************************************/ … … 56 56 57 57 static void componentFree(p_psComponent* comp); 58 static p_psComponent* componentAlloc(const char *name, intlevel);58 static p_psComponent* componentAlloc(const char *name, psS32 level); 59 59 60 60 /***************************************************************************** 61 61 componentAlloc(): allocate memory for a new node, and initialize members. 62 62 *****************************************************************************/ 63 static p_psComponent* componentAlloc(const char *name, intlevel)63 static p_psComponent* componentAlloc(const char *name, psS32 level) 64 64 { 65 65 p_psComponent* comp = psAlloc(sizeof(p_psComponent)); … … 68 68 p_psMemSetDeallocator(comp, (psFreeFcn) componentFree); 69 69 comp->name = psStringCopy(name); 70 p_psMemSetPersistent(( void*)comp->name,true);70 p_psMemSetPersistent((psPtr)comp->name,true); 71 71 comp->level = level; 72 72 comp->n = 0; … … 86 86 87 87 if (comp->subcomp != NULL) { 88 for ( inti = 0; i < comp->n; i++) {88 for (psS32 i = 0; i < comp->n; i++) { 89 89 p_psMemSetPersistent(comp->subcomp[i],false); 90 90 psFree(comp->subcomp[i]); … … 94 94 } 95 95 96 p_psMemSetPersistent(( void*)comp->name,false);97 psFree(( void*)comp->name);96 p_psMemSetPersistent((psPtr)comp->name,false); 97 psFree((psPtr)comp->name); 98 98 } 99 99 … … 115 115 void p_psTraceReset(p_psComponent* currentNode) 116 116 { 117 inti = 0;117 psS32 i = 0; 118 118 119 119 if (NULL == currentNode) { … … 149 149 to ANSI-C. 150 150 *****************************************************************************/ 151 static bool componentAdd(const char *addNodeName, intlevel)152 { 153 inti = 0; // Loop index variable.151 static psBool componentAdd(const char *addNodeName, psS32 level) 152 { 153 psS32 i = 0; // Loop index variable. 154 154 char name[strlen(addNodeName) + 1]; // buffer for writeable copy. 155 155 char *pname = name; 156 156 char *firstComponent = NULL; // first component of name 157 157 p_psComponent* currentNode = cRoot; 158 intnodeExists = 0;158 psS32 nodeExists = 0; 159 159 160 160 // XXX: Verify that this is the correct behavior. … … 240 240 zero 241 241 *****************************************************************************/ 242 bool psTraceSetLevel(const char *comp, // component of interest243 intlevel) // desired trace level242 psBool psTraceSetLevel(const char *comp, // component of interest 243 psS32 level) // desired trace level 244 244 { 245 245 char *compName = NULL; … … 299 299 The trace level of the "name" component. 300 300 *****************************************************************************/ 301 static intdoGetTraceLevel(const char *aname)301 static psS32 doGetTraceLevel(const char *aname) 302 302 { 303 303 char name[strlen(aname) + 1]; // need a writeable copy: for strsep() … … 305 305 char *firstComponent = NULL; // first component of name 306 306 p_psComponent* currentNode = cRoot; 307 inti = 0;308 intdefaultLevel = 0;307 psS32 i = 0; 308 psS32 defaultLevel = 0; 309 309 310 310 if (NULL == currentNode) { … … 365 365 The level of "name" in the root component tree. 366 366 *****************************************************************************/ 367 intpsTraceGetLevel(const char *name)367 psS32 psTraceGetLevel(const char *name) 368 368 { 369 369 char *compName = NULL; 370 inttraceLevel;370 psS32 traceLevel; 371 371 372 372 if (cRoot == NULL) { … … 401 401 *****************************************************************************/ 402 402 static void doPrintTraceLevels(const p_psComponent* comp, 403 intdepth,404 intdefLevel)405 { 406 inti = 0;403 psS32 depth, 404 psS32 defLevel) 405 { 406 psS32 i = 0; 407 407 408 408 if (comp->name[0] == '\0') { … … 472 472 *****************************************************************************/ 473 473 void p_psTrace(const char *comp, // component being traced 474 intlevel, // desired trace level474 psS32 level, // desired trace level 475 475 ...) // arguments 476 476 { 477 477 char *fmt = NULL; 478 478 va_list ap; 479 inti = 0;479 psS32 i = 0; 480 480 481 481 if (NULL == comp) { -
trunk/psLib/src/sysUtils/psTrace.h
r2202 r2204 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10-2 6 23:14:04$11 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-27 00:57:31 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 50 50 { 51 51 const char *name; // last part of name of component 52 intlevel; // trace level for this component53 intn; // number of subcomponents52 psS32 level; // trace level for this component 53 psS32 n; // number of subcomponents 54 54 struct p_psComponent* *subcomp; // next level of subcomponents 55 55 } … … 59 59 /// Send a trace message 60 60 void p_psTrace(const char *facil, ///< facilty of interest 61 intmyLevel, ///< desired trace level61 psS32 myLevel, ///< desired trace level 62 62 ...) ///< trace message arguments 63 63 ; … … 65 65 66 66 /// Set trace level 67 bool psTraceSetLevel(const char *facil, ///< facilty of interest68 intlevel) ///< desired trace level67 psBool psTraceSetLevel(const char *facil, ///< facilty of interest 68 psS32 level) ///< desired trace level 69 69 ; 70 70 71 71 /// Get the trace level 72 intpsTraceGetLevel(const char *facil) ///< facilty of interest72 psS32 psTraceGetLevel(const char *facil) ///< facilty of interest 73 73 ; 74 74 -
trunk/psLib/src/sysUtils/psType.h
r1984 r2204 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-10- 06 21:40:13$13 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-27 00:57:31 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include <stdint.h> 24 24 #include <float.h> 25 #include <stdbool.h> 25 26 26 27 /// @addtogroup DataContainer … … 52 53 typedef float _Complex psC32; ///< complex with 32-bit floating point Real and Imagary numbers 53 54 typedef double _Complex psC64; ///< complex with 64-bit floating point Real and Imagary numbers 54 typedef void *psPTR; ///< void pointer 55 typedef void* psPtr; ///< void pointer 56 typedef bool psBool; ///< boolean value 55 57 56 58 typedef enum { … … 60 62 PS_TYPE_S64 = 0x0108, ///< Long integer. 61 63 PS_TYPE_U8 = 0x0301, ///< Unsigned character. 62 PS_TYPE_U16 = 0x0302, ///< Unsigned shortinteger.64 PS_TYPE_U16 = 0x0302, ///< Unsigned psS16 integer. 63 65 PS_TYPE_U32 = 0x0304, ///< Unsigned integer. 64 PS_TYPE_U64 = 0x0308, ///< Unsigned longinteger.66 PS_TYPE_U64 = 0x0308, ///< Unsigned psS64 integer. 65 67 PS_TYPE_F32 = 0x0404, ///< Single-precision Floating point. 66 68 PS_TYPE_F64 = 0x0408, ///< Double-precision floating point. … … 115 117 #define PS_TYPE_C32_NAME "psC32" 116 118 #define PS_TYPE_C64_NAME "psC64" 117 #define PS_TYPE_PTR_NAME "psP TR"119 #define PS_TYPE_PTR_NAME "psPtr" 118 120 119 121 #define PS_TYPE_NAME(value,type) \ … … 183 185 #define PS_IS_PSELEMTYPE_COMPLEX(x) ((x & 0x800) == 0x800) 184 186 /// Macro to determine the storage size, in bytes, of the psElemType. 185 #define PSELEMTYPE_SIZEOF(x) ( (x==PS_TYPE_PTR) ? sizeof( void*) :(x & 0xFF) )187 #define PSELEMTYPE_SIZEOF(x) ( (x==PS_TYPE_PTR) ? sizeof(psPtr) :(x & 0xFF) ) 186 188 187 189 /** Dimensions of a data type.
Note:
See TracChangeset
for help on using the changeset viewer.
