IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sysUtils/psMemory.h

    r1406 r1407  
    11#if !defined(PS_MEMORY_H)
    2 #define PS_MEMORY_H
     2#    define PS_MEMORY_H
     3
    34/** @file  psMemory.h
    45 *
     
    1415 *  @ingroup MemoryManagement
    1516 *
    16  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-08-06 22:34:05 $
     17 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     18 *  @date $Date: 2004-08-07 00:06:06 $
    1819 *
    1920 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    2021 */
    2122
    22 #include <stdio.h>                      // needed for FILE
    23 #include <stdbool.h>
    24 #include <pthread.h>                    // we need a mutex to make this stuff thread safe.
     23#    include <stdio.h>                     // needed for FILE
     24#    include <stdbool.h>
     25#    include <pthread.h>                   // we need a mutex to make this stuff thread safe.
    2526
    2627/** @addtogroup MemoryManagement
     
    5354
    5455/// typedef for deallocator.
    55 typedef void (*psFreeFcn)(void* ptr);
     56typedef void (*psFreeFcn) (void *ptr);
    5657
    5758/** Book-keeping data for storage allocator.
     
    6263typedef struct psMemBlock
    6364{
    64     const void* startblock;            ///< initialised to p_psMEMMAGIC
    65     struct psMemBlock* previousBlock;  ///< previous block in allocation list
    66     struct psMemBlock* nextBlock;      ///< next block allocation list
    67     psFreeFcn freeFcn;                 ///< deallocator.  If NULL, use generic deallocation.
    68     size_t  userMemorySize;            ///< the size of the user-portion of the memory block
    69     const psMemoryId id;               ///< a unique ID for this allocation
    70     const char* file;                  ///< set from __FILE__ in e.g. p_psAlloc
    71     const int lineno;                  ///< set from __LINE__ in e.g. p_psAlloc
    72     pthread_mutex_t   refCounterMutex; ///< mutex to ensure exclusive access to reference counter
    73     psReferenceCount refCounter;       ///< how many times pointer is referenced
    74     const void* endblock;              ///< initialised to p_psMEMMAGIC
     65    const void *startblock;     // /< initialised to p_psMEMMAGIC
     66    struct psMemBlock *previousBlock;   // /< previous block in allocation list
     67    struct psMemBlock *nextBlock;       // /< next block allocation list
     68    psFreeFcn freeFcn;          // /< deallocator.  If NULL, use generic deallocation.
     69    size_t userMemorySize;      // /< the size of the user-portion of the memory block
     70    const psMemoryId id;        // /< a unique ID for this allocation
     71    const char *file;           // /< set from __FILE__ in e.g. p_psAlloc
     72    const int lineno;           // /< set from __LINE__ in e.g. p_psAlloc
     73    pthread_mutex_t refCounterMutex;    // /< mutex to ensure exclusive access to reference counter
     74    psReferenceCount refCounter;        // /< how many times pointer is referenced
     75    const void *endblock;       // /< initialised to p_psMEMMAGIC
    7576}
    7677psMemBlock;
     
    8182 *  @ingroup memCallback
    8283 */
    83 typedef psMemoryId (*psMemAllocateCallback)(
    84     const psMemBlock *ptr           ///< the psMemBlock just allocated
    85 );
     84typedef psMemoryId(*psMemAllocateCallback) (const psMemBlock * ptr      // /< the psMemBlock just allocated
     85                                           );
    8686
    8787/** prototype of memory free callback used by memory functions
     
    9090 *  @ingroup memCallback
    9191 */
    92 typedef psMemoryId (*psMemFreeCallback)(
    93     const psMemBlock *ptr           ///< the psMemBlock being freed
    94 );
     92typedef psMemoryId(*psMemFreeCallback) (const psMemBlock * ptr  // /< the psMemBlock being freed
     93                                       );
    9594
    9695/** prototype of a callback used in error conditions
     
    101100 *  @ingroup memCallback
    102101 */
    103 typedef void (*psMemProblemCallback)(
    104     const psMemBlock *ptr,          ///< the pointer to the problematic memory block.
    105     const char *file,               ///< the file in which the problem originated
    106     int lineno                      ///< the line number in which the problem originated
    107 );
     102typedef void (*psMemProblemCallback) (const psMemBlock * ptr,   // /< the pointer to the problematic memory
     103                                      // block.
     104                                      const char *file, // /< the file in which the problem originated
     105                                      int lineno        // /< the line number in which the problem originated
     106                                     );
    108107
    109108/** prototype of a callback function used when memory runs out
     
    115114 *  @ingroup memCallback
    116115 */
    117 typedef void *(*psMemExhaustedCallback)(
    118     size_t size                     //< the size of buffer required
    119 );
     116typedef void *(*psMemExhaustedCallback) (size_t size    // < the size of buffer required
     117                                        );
    120118
    121119/** Memory allocation.  This operates much like malloc(), but is guaranteed to return a non-NULL value.
     
    124122 *  @see psFree
    125123 */
    126 #ifdef DOXYGEN
    127 void* psAlloc(
    128     size_t size                     ///< Size required
    129 );
    130 #else
    131 void* p_psAlloc(
    132     size_t size,                    ///< Size required
    133     const char *file,               ///< File of call
    134     int lineno                      ///< Line number of call
    135 );
    136 
    137 void p_psMemSetDeallocator(void* ptr, psFreeFcn freeFcn);
    138 psFreeFcn p_psMemGetDeallocator(void* ptr);
     124#    ifdef DOXYGEN
     125void *psAlloc(size_t size       // /< Size required
     126             );
     127#    else
     128    void *p_psAlloc(size_t size,    // /< Size required
     129                    const char *file,       // /< File of call
     130                    int lineno      // /< Line number of call
     131                   );
     132
     133void p_psMemSetDeallocator(void *ptr, psFreeFcn freeFcn);
     134psFreeFcn p_psMemGetDeallocator(void *ptr);
    139135
    140136/// Memory allocation. psAlloc sends file and line number to p_psAlloc.
    141 #define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)
    142 #endif
    143 
     137#        define psAlloc(size) p_psAlloc(size, __FILE__, __LINE__)
     138#    endif
    144139
    145140/** Memory re-allocation.  This operates much like realloc(), but is guaranteed to return a non-NULL value.
     
    148143 *  @see psAlloc, psFree
    149144 */
    150 #ifdef DOXYGEN
    151 void* psRealloc(void *ptr               ///< Pointer to re-allocate
    152                 size_t size,            ///< Size required
     145#    ifdef DOXYGEN
     146void *psRealloc(void *ptr       // /< Pointer to re-allocate
     147                size_t size,    // /< Size required
    153148               );
    154 #else
    155 void* p_psRealloc(void *ptr,            ///< Pointer to re-allocate
    156                   size_t size,          ///< Size required
    157                   const char *file,     ///< File of call
    158                   int lineno            ///< Line number of call
     149#    else
     150    void *p_psRealloc(void *ptr,    // /< Pointer to re-allocate
     151                      size_t size,  // /< Size required
     152                      const char *file,     // /< File of call
     153                      int lineno    // /< Line number of call
     154                     );
     155
     156/// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
     157#        define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__)
     158
     159#    endif
     160
     161/** Free memory.  This operates much like free().
     162 *
     163 *  @see psAlloc, psRealloc
     164 */
     165#    ifdef DOXYGEN
     166void psFree(void *ptr,          // /< Pointer to free, if NULL, function returns immediately.
     167           );
     168#    else
     169    void p_psFree(void *ptr,        // /< Pointer to free
     170                  const char *file, // /< File of call
     171                  int lineno        // /< Line number of call
    159172                 );
    160173
    161 /// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
    162 #define psRealloc(ptr, size) p_psRealloc(ptr, size, __FILE__, __LINE__)
    163 
    164 #endif
    165 
    166 
    167 /** Free memory.  This operates much like free().
    168  *
    169  *  @see psAlloc, psRealloc
    170  */
    171 #ifdef DOXYGEN
    172 void psFree(void *ptr,                  ///< Pointer to free, if NULL, function returns immediately.
    173            );
    174 #else
    175 void p_psFree(void *ptr,                ///< Pointer to free
    176               const char *file,         ///< File of call
    177               int lineno                ///< Line number of call
    178              );
    179 
    180174/// Free memory.  psFree sends file and line number to p_psFree.
    181 #define psFree(size) p_psFree(size, __FILE__, __LINE__)
    182 
    183 #endif
     175#        define psFree(size) p_psFree(size, __FILE__, __LINE__)
     176
     177#    endif
    184178
    185179/** Check for memory leaks.  This scans for allocated memory buffers not freed with an ID not less than id0.
     
    197191 *  @ingroup memTracing
    198192 */
    199 int psMemCheckLeaks(
    200     psMemoryId id0,              ///< don't list blocks with id < id0
    201     psMemBlock ***arr,              ///< pointer to array of pointers to leaked blocks, or NULL
    202     FILE *fd                        ///< print list of leaks to fd (or NULL)
    203 );
     193int psMemCheckLeaks(psMemoryId id0,     // /< don't list blocks with id < id0
     194                    psMemBlock *** arr, // /< pointer to array of pointers to leaked blocks, or NULL
     195                    FILE * fd   // /< print list of leaks to fd (or NULL)
     196                   );
    204197
    205198/** Check for memory corruption.  Scans all currently allocated memory buffers and checks for corruptions,
     
    208201 *  @ingroup memTracing
    209202 */
    210 int psMemCheckCorruption(
    211     bool abort_on_error              ///< Abort on detecting corruption?
    212 );
     203int psMemCheckCorruption(bool abort_on_error    // /< Abort on detecting corruption?
     204                        );
    213205
    214206/** Return reference counter
     
    216208 *  @ingroup memRefCount
    217209 */
    218 psReferenceCount psMemGetRefCounter(
    219     void *vptr                      ///< Pointer to get refCounter for
    220 );
     210psReferenceCount psMemGetRefCounter(void *vptr  // /< Pointer to get refCounter for
     211                                   );
    221212
    222213/** Increment reference counter and return the pointer
     
    224215 *  @ingroup memRefCount
    225216 */
    226 #ifdef DOXYGEN
    227 void* psMemIncrRefCounter(
    228     void *vptr                         ///< Pointer to increment refCounter, and return
    229 );
    230 #else
    231 void* p_psMemIncrRefCounter(
    232     void *vptr,                        ///< Pointer to increment refCounter, and return
    233     const char *file,                  ///< File of call
    234     int lineno                         ///< Line number of call
    235 );
    236 #define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)
    237 #endif
     217#    ifdef DOXYGEN
     218void *psMemIncrRefCounter(void *vptr    // /< Pointer to increment refCounter, and return
     219                         );
     220#    else
     221    void *p_psMemIncrRefCounter(void *vptr, // /< Pointer to increment refCounter, and return
     222                                const char *file,   // /< File of call
     223                                int lineno  // /< Line number of call
     224                               );
     225
     226#        define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)
     227#    endif
    238228
    239229/** Decrement reference counter and return the pointer
     
    241231 *  @ingroup memRefCount
    242232 */
    243 #ifdef DOXYGEN
    244 void* psMemDecrRefCounter(
    245     void *vptr                         ///< Pointer to decrement refCounter, and return
    246 );
    247 #else
    248 void* p_psMemDecrRefCounter(
    249     void *vptr,                        ///< Pointer to decrement refCounter, and return
    250     const char *file,                  ///< File of call
    251     int lineno                         ///< Line number of call
    252 );
    253 #define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)
    254 #endif
     233#    ifdef DOXYGEN
     234void *psMemDecrRefCounter(void *vptr    // /< Pointer to decrement refCounter, and return
     235                         );
     236#    else
     237    void *p_psMemDecrRefCounter(void *vptr, // /< Pointer to decrement refCounter, and return
     238                                const char *file,   // /< File of call
     239                                int lineno  // /< Line number of call
     240                               );
     241
     242#        define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)
     243#    endif
    255244
    256245/** Set callback for problems
    257246 *  @ingroup memCallback
    258247 */
    259 psMemProblemCallback psMemProblemCallbackSet(
    260     psMemProblemCallback func       ///< Function to run
    261 );
     248psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func  // /< Function to run
     249                                            );
    262250
    263251/** Set callback for out-of-memory
     
    265253 *  @ingroup memCallback
    266254 */
    267 psMemExhaustedCallback psMemExhaustedCallbackSet(
    268     psMemExhaustedCallback func     ///< Function to run
    269 );
     255psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func    // /< Function to run
     256                                                );
    270257
    271258/** Set call back for when a particular memory block is allocated
     
    273260 *  @ingroup memCallback
    274261 */
    275 psMemAllocateCallback psMemAllocateCallbackSet(
    276     psMemAllocateCallback func          ///< Function to run
    277 );
     262psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func       // /< Function to run
     263                                              );
    278264
    279265/** Set call back for when a particular memory block is freed
     
    281267 *  @ingroup memCallback
    282268 */
    283 psMemFreeCallback psMemFreeCallbackSet(
    284     psMemFreeCallback func              ///< Function to run
    285 );
     269psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func   // /< Function to run
     270                                      );
    286271
    287272/** get next memory ID
     
    295280 *  @ingroup memCallback
    296281 */
    297 psMemoryId psMemAllocateCallbackSetID(
    298     psMemoryId id                       ///< ID to set
    299 );
     282psMemoryId psMemAllocateCallbackSetID(psMemoryId id     // /< ID to set
     283                                     );
    300284
    301285/** set p_psMemFreeID to id
     
    303287 *  @ingroup memCallback
    304288 */
    305 psMemoryId psMemFreeCallbackSetID(
    306     psMemoryId id                       ///< ID to set
    307 );
     289psMemoryId psMemFreeCallbackSetID(psMemoryId id // /< ID to set
     290                                 );
    308291
    309292//@} End of Memory Management Functions
    310293
    311 #ifndef DOXYGEN
     294#    ifndef DOXYGEN
    312295
    313296/*
    314297 * Ensure that any program using malloc/realloc/free will fail to compile
    315298 */
    316 #ifndef PS_ALLOW_MALLOC
    317 #ifdef __GNUC__
    318 #pragma GCC poison malloc realloc calloc free
    319 #else
    320 #define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
    321 #define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
    322 #define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
    323 #define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
    324 #endif
    325 #endif
    326 
    327 #endif // doxygen skip
    328 
    329 #endif // end of header file
     299#        ifndef PS_ALLOW_MALLOC
     300#            ifdef __GNUC__
     301#                pragma GCC poison malloc realloc calloc free
     302#            else
     303    #                define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
     304    #                define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
     305    #                define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
     306    #                define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
     307    #            endif
     308    #        endif
     309
     310    #    endif
     311    // doxygen skip
     312
     313    #endif // end of header file
Note: See TracChangeset for help on using the changeset viewer.