Changeset 4444
- Timestamp:
- Jun 30, 2005, 5:57:42 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 5 edited
-
src/sysUtils/psMemory.c (modified) (11 diffs)
-
src/sysUtils/psMemory.h (modified) (18 diffs)
-
src/sysUtils/psType.h (modified) (2 diffs)
-
test/sysUtils/tst_psMemory.c (modified) (6 diffs)
-
test/sysUtils/verified/tst_psMemory.stderr (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psMemory.c
r4401 r4444 8 8 * @author Robert Lupton, Princeton University 9 9 * 10 * @version $Revision: 1.5 7$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-0 6-27 20:38:12$10 * @version $Revision: 1.58 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-07-01 03:57:39 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 84 84 /* 85 85 * Default callback for both allocate and free. Note that the 86 * value of p_psMemAlloc ateID/p_psMemFreeID is incremented86 * value of p_psMemAllocID/p_psMemFreeID is incremented 87 87 * by the return value (so returning 0 means that the callback 88 88 * isn't resignalled) 89 89 */ 90 static psMemId memAlloc ateCallbackDefault(const psMemBlock* ptr)91 { 92 static psMemId incr = 0; // "p_psMemAlloc ateID += incr"90 static psMemId memAllocCallbackDefault(const psMemBlock* ptr) 91 { 92 static psMemId incr = 0; // "p_psMemAllocID += incr" 93 93 94 94 return incr; … … 102 102 } 103 103 104 static void memProblemCallbackDefault( const psMemBlock* ptr, const char *file, psS32lineno)104 static void memProblemCallbackDefault( psMemBlock* ptr, const char *file, unsigned int lineno) 105 105 { 106 106 if (ptr->refCounter < 1) { … … 158 158 * The default callbacks 159 159 */ 160 static psMemAlloc ateCallback memAllocateCallback = memAllocateCallbackDefault;160 static psMemAllocCallback memAllocCallback = memAllocCallbackDefault; 161 161 static psMemFreeCallback memFreeCallback = memFreeCallbackDefault; 162 162 static psMemProblemCallback memProblemCallback = memProblemCallbackDefault; … … 194 194 * Call the callbacks when these IDs are allocated/freed 195 195 */ 196 psMemId p_psMemAlloc ateID = 0; // notify user this block is allocated196 psMemId p_psMemAllocID = 0; // notify user this block is allocated 197 197 psMemId p_psMemFreeID = 0; // notify user this block is freed 198 198 199 psMemId psMemAlloc ateCallbackSetID(psMemId id)200 { 201 psMemId old = p_psMemAlloc ateID;202 203 p_psMemAlloc ateID = id;199 psMemId psMemAllocCallbackSetID(psMemId id) 200 { 201 psMemId old = p_psMemAllocID; 202 203 p_psMemAllocID = id; 204 204 205 205 return old; … … 215 215 } 216 216 217 psMemAlloc ateCallback psMemAllocateCallbackSet(psMemAllocateCallback func)218 { 219 psMemFreeCallback old = memAlloc ateCallback;217 psMemAllocCallback psMemAllocCallbackSet(psMemAllocCallback func) 218 { 219 psMemFreeCallback old = memAllocCallback; 220 220 221 221 if (func != NULL) { 222 memAlloc ateCallback = func;222 memAllocCallback = func; 223 223 } else { 224 memAlloc ateCallback = memAllocateCallbackDefault;224 memAllocCallback = memAllocCallbackDefault; 225 225 } 226 226 … … 286 286 } 287 287 288 psPtr p_psAlloc(size_t size, const char *file, psS32lineno)288 psPtr p_psAlloc(size_t size, const char *file, unsigned int lineno) 289 289 { 290 290 … … 363 363 364 364 // Did the user ask to be informed about this allocation? 365 if (ptr->id == p_psMemAlloc ateID) {366 p_psMemAlloc ateID += memAllocateCallback(ptr);365 if (ptr->id == p_psMemAllocID) { 366 p_psMemAllocID += memAllocCallback(ptr); 367 367 } 368 368 // And return the user the memory that they allocated … … 370 370 } 371 371 372 psPtr p_psRealloc(psPtr vptr, size_t size, const char *file, psS32lineno)372 psPtr p_psRealloc(psPtr vptr, size_t size, const char *file, unsigned int lineno) 373 373 { 374 374 size = (size < recycleBinSize[0]) ? recycleBinSize[0] : size; // set the minimum size to allocate … … 416 416 417 417 // Did the user ask to be informed about this allocation? 418 if (ptr->id == p_psMemAlloc ateID) {419 p_psMemAlloc ateID += memAllocateCallback(ptr);418 if (ptr->id == p_psMemAllocID) { 419 p_psMemAllocID += memAllocCallback(ptr); 420 420 } 421 421 … … 424 424 } 425 425 426 void p_psFree(psPtr vptr, const char *file, psS32lineno)426 void p_psFree(psPtr vptr, const char *file, unsigned int lineno) 427 427 { 428 428 if (vptr == NULL) { -
trunk/psLib/src/sysUtils/psMemory.h
r4401 r4444 12 12 * @ingroup MemoryManagement 13 13 * 14 * @version $Revision: 1.4 4$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-0 6-27 20:38:12$14 * @version $Revision: 1.45 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-07-01 03:57:39 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 49 49 50 50 /// typedef for memory identification numbers. Guaranteed to be some variety of integer. 51 typedef psU64psMemId;51 typedef unsigned long psMemId; 52 52 53 53 /// typedef for a memory block's reference count. Guaranteed to be some variety of integer. 54 typedef psU64psReferenceCount;54 typedef unsigned long psReferenceCount; 55 55 56 56 /// typedef for deallocator. 57 typedef void (*psFreeFunc) ( psPtrptr);57 typedef void (*psFreeFunc) (void* ptr); 58 58 59 59 /** Book-keeping data for storage allocator. … … 64 64 typedef struct psMemBlock 65 65 { 66 const psPtrstartblock; ///< initialised to p_psMEMMAGIC66 const void* startblock; ///< initialised to p_psMEMMAGIC 67 67 struct psMemBlock* previousBlock; ///< previous block in allocation list 68 68 struct psMemBlock* nextBlock; ///< next block allocation list … … 71 71 const psMemId id; ///< a unique ID for this allocation 72 72 const char *file; ///< set from __FILE__ in e.g. p_psAlloc 73 const psS32 lineno;///< set from __LINE__ in e.g. p_psAlloc73 const unsigned int lineno; ///< set from __LINE__ in e.g. p_psAlloc 74 74 pthread_mutex_t refCounterMutex; ///< mutex to ensure exclusive access to reference counter 75 75 psReferenceCount refCounter; ///< how many times pointer is referenced 76 psBool persistent;///< marks if this non-user persistent data like error stack, etc.77 const psPtrendblock; ///< initialised to p_psMEMMAGIC76 bool persistent; ///< marks if this non-user persistent data like error stack, etc. 77 const void* endblock; ///< initialised to p_psMEMMAGIC 78 78 } 79 79 psMemBlock; … … 81 81 /** prototype of a basic callback used by memory functions 82 82 * 83 * @see psMemAlloc ateCallbackSet84 * @ingroup memCallback 85 */ 86 typedef psMemId(*psMemAlloc ateCallback) (83 * @see psMemAllocCallbackSet 84 * @ingroup memCallback 85 */ 86 typedef psMemId(*psMemAllocCallback) ( 87 87 const psMemBlock* ptr ///< the psMemBlock just allocated 88 88 ); … … 105 105 */ 106 106 typedef void (*psMemProblemCallback) ( 107 const psMemBlock* ptr,///< the pointer to the problematic memory block.108 const char *file ,///< the file in which the problem originated109 psS32 lineno///< the line number in which the problem originated107 psMemBlock* ptr, ///< the pointer to the problematic memory block. 108 const char *filename, ///< the file in which the problem originated 109 unsigned int lineno ///< the line number in which the problem originated 110 110 ); 111 111 … … 118 118 * @ingroup memCallback 119 119 */ 120 typedef psPtr(*psMemExhaustedCallback) (120 typedef void* (*psMemExhaustedCallback) ( 121 121 size_t size ///< the size of buffer required 122 122 ); … … 128 128 */ 129 129 #ifdef DOXYGEN 130 psPtr psAlloc(size_t size ///< Size required 131 ); 130 131 psPtr psAlloc( 132 size_t size ///< Size required 133 ); 134 132 135 #else // #ifdef DOXYGEN 133 psPtr p_psAlloc(size_t size, ///< Size required 134 const char *file, ///< File of call 135 psS32 lineno ///< Line number of call 136 ); 136 psPtr p_psAlloc( 137 size_t size, ///< Size required 138 const char *filename, ///< File of call 139 unsigned int lineno ///< Line number of call 140 ); 137 141 138 142 /// Memory allocation. psAlloc sends file and line number to p_psAlloc. … … 203 207 */ 204 208 #ifdef DOXYGEN 209 205 210 psPtr psRealloc( 206 psPtr ptr, ///< Pointer to re-allocate207 size_t size ///< Size required211 psPtr ptr, ///< Pointer to re-allocate 212 size_t size ///< Size required 208 213 ); 209 214 #else // #ifdef DOXYGEN 215 210 216 psPtr p_psRealloc( 211 217 psPtr ptr, ///< Pointer to re-allocate 212 218 size_t size, ///< Size required 213 const char *file ,///< File of call214 psS32 lineno///< Line number of call219 const char *filename, ///< File of call 220 unsigned int lineno ///< Line number of call 215 221 ); 216 222 … … 234 240 psPtr ptr, ///< Pointer to free 235 241 const char *file, ///< File of call 236 psS32 lineno///< Line number of call242 unsigned int lineno ///< Line number of call 237 243 ); 238 244 … … 259 265 */ 260 266 psS32 psMemCheckLeaks( 261 psMemId id0, ///< don't list blocks with id < id0267 psMemId id0, ///< don't list blocks with id < id0 262 268 psMemBlock* ** arr, ///< pointer to array of pointers to leaked blocks, or NULL 263 269 FILE * fd, ///< print list of leaks to fd (or NULL) … … 288 294 #ifdef DOXYGEN 289 295 psPtr psMemIncrRefCounter( 290 const psPtr ptr ///< Pointer to increment refCounter, and return296 const psPtr ptr ///< Pointer to increment refCounter, and return 291 297 ); 292 298 #else … … 294 300 psPtr vptr, ///< Pointer to increment refCounter, and return 295 301 const char *file, ///< File of call 296 psS32 lineno ///< Line number of call302 psS32 lineno ///< Line number of call 297 303 ); 298 304 … … 318 324 psPtr vptr, ///< Pointer to decrement refCounter, and return 319 325 const char *file, ///< File of call 320 psS32 lineno ///< Line number of call326 psS32 lineno ///< Line number of call 321 327 ); 322 328 … … 362 368 /** Set call back for when a particular memory block is allocated 363 369 * 364 * A private variable, p_psMemAlloc ateID, can be used to trace the allocation365 * and freeing of specific memory blocks. If p_psMemAlloc ateID is set and a366 * memory block with that ID is allocated, psMemAlloc ateCallback is called370 * A private variable, p_psMemAllocID, can be used to trace the allocation 371 * and freeing of specific memory blocks. If p_psMemAllocID is set and a 372 * memory block with that ID is allocated, psMemAllocCallback is called 367 373 * just before memory is returned to the calling function. 368 374 * 369 375 * @ingroup memCallback 370 376 * 371 * @return psMemAlloc ateCallback old psMemAllocateCallback function372 */ 373 psMemAlloc ateCallback psMemAllocateCallbackSet(374 psMemAlloc ateCallback func///< Function to run at memory allocation of specific mem block377 * @return psMemAllocCallback old psMemAllocCallback function 378 */ 379 psMemAllocCallback psMemAllocCallbackSet( 380 psMemAllocCallback func ///< Function to run at memory allocation of specific mem block 375 381 ); 376 382 … … 398 404 psMemId psMemGetId(void); 399 405 400 /** set p_psMemAlloc ateID to specific id401 * 402 * A private variable, p_psMemAlloc ateID, can be used to trace the allocation403 * and freeing of specific memory blocks. If p_psMemAlloc ateID is set and a404 * memory block with that ID is allocated, psMemAlloc ateCallback is called406 /** set p_psMemAllocID to specific id 407 * 408 * A private variable, p_psMemAllocID, can be used to trace the allocation 409 * and freeing of specific memory blocks. If p_psMemAllocID is set and a 410 * memory block with that ID is allocated, psMemAllocCallback is called 405 411 * just before memory is returned to the calling function. 406 412 * … … 409 415 * @return psMemId 410 416 * 411 * @see psMemAlloc ateCallbackSet412 */ 413 psMemId psMemAlloc ateCallbackSetID(414 psMemId id ///< ID to set417 * @see psMemAllocCallbackSet 418 */ 419 psMemId psMemAllocCallbackSetID( 420 psMemId id ///< ID to set 415 421 ); 416 422 … … 429 435 */ 430 436 psMemId psMemFreeCallbackSetID( 431 psMemId id ///< ID to set437 psMemId id ///< ID to set 432 438 ); 433 439 -
trunk/psLib/src/sysUtils/psType.h
r4342 r4444 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-0 6-22 02:05:41$12 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-07-01 03:57:39 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 94 94 } psElemType; 95 95 96 /** Enumeration primarily used with metadata which defines a data structure 97 * e.g., list, array, FITS file, etc. 98 */ 99 typedef enum { 100 PS_DATA_S32 = PS_TYPE_S32, ///< psS32 101 PS_DATA_F32 = PS_TYPE_F32, ///< psF32 102 PS_DATA_F64 = PS_TYPE_F64, ///< psF64 103 PS_DATA_BOOL = PS_TYPE_BOOL, ///< psBool 104 PS_DATA_STRING = 0x10000, ///< psString (char *) 105 PS_DATA_ARRAY, ///< psArray 106 PS_DATA_BITSET, ///< psBitSet 107 PS_DATA_CELL, ///< psCell 108 PS_DATA_CHIP, ///< psChip 109 PS_DATA_CUBE, ///< psCube 110 PS_DATA_FITS, ///< psFits 111 PS_DATA_HASH, ///< psHash 112 PS_DATA_HISTOGRAM, ///< psHistogram 113 PS_DATA_IMAGE, ///< psImage 114 PS_DATA_KERNEL, ///< psKernel 115 PS_DATA_LIST, ///< psList 116 PS_DATA_LOOKUPTABLE, ///< psLookupTable 117 PS_DATA_METADATA, ///< psMetadata 118 PS_DATA_METADATAITEM, ///< psMetadataItem 119 PS_DATA_MINIMIZATION, ///< psMinimization 120 PS_DATA_PIXELS, ///< psPixels 121 PS_DATA_PLANE, ///< psPlane 122 PS_DATA_PLANEDISTORT, ///< psPlaneDistort 123 PS_DATA_PLANETRANSFORM, ///< psPlaneTransform 124 PS_DATA_POLYNOMIAL1D, ///< psPolynomial1D 125 PS_DATA_POLYNOMIAL2D, ///< psPolynomial2D 126 PS_DATA_POLYNOMIAL3D, ///< psPolynomial3D 127 PS_DATA_POLYNOMIAL4D, ///< psPolynomial4D 128 PS_DATA_PROJECTION, ///< psProjection 129 PS_DATA_READOUT, ///< psReadout 130 PS_DATA_REGION, ///< psRegion 131 PS_DATA_SCALAR, ///< psScalar 132 PS_DATA_SPHERE, ///< psSphere 133 PS_DATA_SPHERETRANSFORM, ///< psSphereTransform 134 PS_DATA_SPLINE1D, ///< psSpline1D 135 PS_DATA_STATS, ///< psStats 136 PS_DATA_TIME, ///< psTime 137 PS_DATA_VECTOR, ///< psVector 138 PS_DATA_UNKNOWN, ///< Other data of an unknown type 139 PS_DATA_METADATA_MULTI ///< Used internally for metadata; not a 'real' type 140 } psDataType; 141 96 142 #define PS_TYPE_MASK PS_TYPE_U8 /**< the psElemType to use for mask image */ 97 143 #define PS_TYPE_MASK_DATA U8 /**< the data member to use for mask image */ -
trunk/psLib/test/sysUtils/tst_psMemory.c
r4397 r4444 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-0 6-25 03:32:42 $8 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-07-01 03:57:42 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 static psS32 TPrealloc( void ); 31 31 static psS32 TPallocCallback( void ); 32 static psMemId memAlloc ateCallback( const psMemBlock *ptr );32 static psMemId memAllocCallback( const psMemBlock *ptr ); 33 33 static psMemId memFreeCallback( const psMemBlock *ptr ); 34 34 static psS32 TPcheckLeaks( void ); 35 35 static psS32 TPmemCorruption( void ); 36 36 static psS32 TPmultipleFree( void ); 37 void memProblemCallback( const psMemBlock *ptr, const char *file, psS32lineno );37 void memProblemCallback( psMemBlock *ptr, const char *filename, unsigned int lineno ); 38 38 39 39 static psS32 problemCallbackCalled = 0; … … 289 289 allocCallbackCalled = 0; 290 290 freeCallbackCalled = 0; 291 psMemAlloc ateCallbackSet( memAllocateCallback );291 psMemAllocCallbackSet( memAllocCallback ); 292 292 psMemFreeCallbackSet( memFreeCallback ); 293 293 294 psMemAlloc ateCallbackSetID( currentId + 1 );294 psMemAllocCallbackSetID( currentId + 1 ); 295 295 psMemFreeCallbackSetID( currentId + 1 ); 296 296 … … 320 320 mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) ); 321 321 322 psMemAlloc ateCallbackSetID( mark );322 psMemAllocCallbackSetID( mark ); 323 323 324 324 mem1 = ( psS32* ) psRealloc( mem1, initialSize * 2 * sizeof( psS32 ) ); … … 489 489 } 490 490 491 void memProblemCallback( const psMemBlock *ptr, const char *file, psS32lineno )491 void memProblemCallback( psMemBlock *ptr, const char *file, unsigned int lineno ) 492 492 { 493 493 psLogMsg( __func__, PS_LOG_INFO, "memory callback called for id %lld (%s:%d).", … … 497 497 } 498 498 499 psMemId memAlloc ateCallback( const psMemBlock *ptr )499 psMemId memAllocCallback( const psMemBlock *ptr ) 500 500 { 501 501 psLogMsg( __func__, PS_LOG_INFO, "block %lld was (re)allocated", ptr->id ); -
trunk/psLib/test/sysUtils/verified/tst_psMemory.stderr
r3246 r4444 63 63 <DATE><TIME>|<HOST>|I|TPallocCallback 64 64 call to psAlloc/psRealloc shall generate a callback if specified memory ID is allocated. 65 <DATE><TIME>|<HOST>|I|memAlloc ateCallback65 <DATE><TIME>|<HOST>|I|memAllocCallback 66 66 block 2 was (re)allocated 67 <DATE><TIME>|<HOST>|I|memAlloc ateCallback67 <DATE><TIME>|<HOST>|I|memAllocCallback 68 68 block 3 was (re)allocated 69 69 <DATE><TIME>|<HOST>|I|memFreeCallback … … 71 71 <DATE><TIME>|<HOST>|I|memFreeCallback 72 72 block 3 was freed 73 <DATE><TIME>|<HOST>|I|memAlloc ateCallback73 <DATE><TIME>|<HOST>|I|memAllocCallback 74 74 block 4 was (re)allocated 75 <DATE><TIME>|<HOST>|I|memAlloc ateCallback75 <DATE><TIME>|<HOST>|I|memAllocCallback 76 76 block 4 was (re)allocated 77 77 <DATE><TIME>|<HOST>|I|memFreeCallback
Note:
See TracChangeset
for help on using the changeset viewer.
