IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 9, 2004, 3:55:34 PM (22 years ago)
Author:
desonia
Message:

more doxygen-related cleanup

File:
1 edited

Legend:

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

    r1441 r1448  
    1 #if !defined(PS_MEMORY_H)
    2 #define PS_MEMORY_H
    3 
    41/** @file  psMemory.h
    52 *
     
    1512 *  @ingroup MemoryManagement
    1613 *
    17  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    18  *  @date $Date: 2004-08-09 23:40:55 $
     14 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-08-10 01:55:34 $
    1916 *
    2017 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    2118 */
     19
     20#if !defined(PS_MEMORY_H)
     21#define PS_MEMORY_H
    2222
    2323#include <stdio.h>                     // needed for FILE
     
    6363typedef struct psMemBlock
    6464{
    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
     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
    7676}
    7777psMemBlock;
     
    8282 *  @ingroup memCallback
    8383 */
    84 typedef psMemoryId(*psMemAllocateCallback) (const psMemBlock* ptr      ///< the psMemBlock just allocated
    85                                            );
     84typedef psMemoryId(*psMemAllocateCallback) (
     85    const psMemBlock* ptr              ///< the psMemBlock just allocated
     86);
    8687
    8788/** prototype of memory free callback used by memory functions
     
    9091 *  @ingroup memCallback
    9192 */
    92 typedef psMemoryId(*psMemFreeCallback) (const psMemBlock* ptr  ///< the psMemBlock being freed
    93                                        );
     93typedef psMemoryId(*psMemFreeCallback) (
     94    const psMemBlock* ptr              ///< the psMemBlock being freed
     95);
    9496
    9597/** prototype of a callback used in error conditions
     
    100102 *  @ingroup memCallback
    101103 */
    102 typedef 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                                      );
     104typedef void (*psMemProblemCallback) (
     105    const psMemBlock* ptr,             ///< the pointer to the problematic memory block.
     106    const char *file,                  ///< the file in which the problem originated
     107    int lineno                         ///< the line number in which the problem originated
     108);
    107109
    108110/** prototype of a callback function used when memory runs out
     
    114116 *  @ingroup memCallback
    115117 */
    116 typedef void *(*psMemExhaustedCallback) (size_t size    // < the size of buffer required
    117                                         );
     118typedef void *(*psMemExhaustedCallback) (
     119    size_t size                        ///< the size of buffer required
     120);
    118121
    119122/** Memory allocation.  This operates much like malloc(), but is guaranteed to return a non-NULL value.
     
    145148 */
    146149#ifdef DOXYGEN
    147 void *psRealloc(void *ptr       ///< Pointer to re-allocate
    148                 size_t size,    ///< Size required
    149                );
    150 #else
    151 
    152 void *p_psRealloc(void *ptr,    ///< Pointer to re-allocate
    153                   size_t size,  ///< Size required
    154                   const char *file,     ///< File of call
    155                   int lineno    ///< Line number of call
    156                  );
     150void *psRealloc(
     151    void *ptr                          ///< Pointer to re-allocate
     152    size_t size,                       ///< Size required
     153);
     154#else
     155
     156void *p_psRealloc(
     157    void *ptr,                         ///< Pointer to re-allocate
     158    size_t size,                       ///< Size required
     159    const char *file,                  ///< File of call
     160    int lineno                         ///< Line number of call
     161);
    157162
    158163/// Memory re-allocation.  psRealloc sends file and line number to p_psRealloc.
     
    166171 */
    167172#ifdef DOXYGEN
    168 void psFree(void *ptr,          ///< Pointer to free, if NULL, function returns immediately.
    169            );
    170 #else
    171 
    172 void p_psFree(void *ptr,        ///< Pointer to free
    173               const char *file, ///< File of call
    174               int lineno        ///< Line number of call
    175              );
     173void psFree(
     174    void *ptr,                         ///< Pointer to free, if NULL, function returns immediately.
     175);
     176#else
     177
     178void p_psFree(
     179    void *ptr,                        ///< Pointer to free
     180    const char *file,                 ///< File of call
     181    int lineno                        ///< Line number of call
     182);
    176183
    177184/// Free memory.  psFree sends file and line number to p_psFree.
     
    194201 *  @ingroup memTracing
    195202 */
    196 int psMemCheckLeaks(psMemoryId id0,     ///< don't list blocks with id < id0
    197                     psMemBlock* ** arr, ///< pointer to array of pointers to leaked blocks, or NULL
    198                     FILE * fd   ///< print list of leaks to fd (or NULL)
    199                    );
     203int psMemCheckLeaks(
     204    psMemoryId id0,                    ///< don't list blocks with id < id0
     205    psMemBlock* ** arr,                ///< pointer to array of pointers to leaked blocks, or NULL
     206    FILE * fd                          ///< print list of leaks to fd (or NULL)
     207);
    200208
    201209/** Check for memory corruption.  Scans all currently allocated memory buffers and checks for corruptions,
     
    204212 *  @ingroup memTracing
    205213 */
    206 int psMemCheckCorruption(bool abort_on_error    ///< Abort on detecting corruption?
    207                         );
     214int psMemCheckCorruption(
     215    bool abort_on_error                ///< Abort on detecting corruption?
     216);
    208217
    209218/** Return reference counter
     
    211220 *  @ingroup memRefCount
    212221 */
    213 psReferenceCount psMemGetRefCounter(void *vptr  ///< Pointer to get refCounter for
    214                                    );
     222psReferenceCount psMemGetRefCounter(
     223    void *vptr                         ///< Pointer to get refCounter for
     224);
    215225
    216226/** Increment reference counter and return the pointer
     
    219229 */
    220230#ifdef DOXYGEN
    221 void *psMemIncrRefCounter(void *vptr    ///< Pointer to increment refCounter, and return
    222                          );
    223 #else
    224 
    225 void *p_psMemIncrRefCounter(void *vptr, ///< Pointer to increment refCounter, and return
    226                             const char *file,   ///< File of call
    227                             int lineno  ///< Line number of call
    228                            );
     231void *psMemIncrRefCounter(
     232    void *vptr                         ///< Pointer to increment refCounter, and return
     233);
     234#else
     235
     236void *p_psMemIncrRefCounter(
     237    void *vptr,                        ///< Pointer to increment refCounter, and return
     238    const char *file,                  ///< File of call
     239    int lineno                         ///< Line number of call
     240);
    229241
    230242#define psMemIncrRefCounter(vptr) p_psMemIncrRefCounter(vptr, __FILE__, __LINE__)
     
    234246 *
    235247 *  @ingroup memRefCount
    236  */
    237 #ifdef DOXYGEN
    238 void *psMemDecrRefCounter(void *vptr    ///< Pointer to decrement refCounter, and return
    239                          );
    240 #else
    241 
    242 void *p_psMemDecrRefCounter(void *vptr, ///< Pointer to decrement refCounter, and return
    243                             const char *file,   ///< File of call
    244                             int lineno  ///< Line number of call
    245                            );
     248 *
     249 *  @return void*    the pointer deremented in refCount, or NULL if pointer is
     250 *                   fully dereferenced.
     251 */
     252#ifdef DOXYGEN
     253void* psMemDecrRefCounter(
     254    void* vptr                         ///< Pointer to decrement refCounter, and return
     255);
     256#else
     257
     258void *p_psMemDecrRefCounter(
     259    void *vptr,                        ///< Pointer to decrement refCounter, and return
     260    const char *file,                  ///< File of call
     261    int lineno                         ///< Line number of call
     262);
    246263
    247264#define psMemDecrRefCounter(vptr) p_psMemDecrRefCounter(vptr, __FILE__, __LINE__)
    248265#endif
    249266
    250 /** Set callback for problems
    251  *  @ingroup memCallback
    252  */
    253 psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func  ///< Function to run
    254                                             );
    255 
    256 /** Set callback for out-of-memory
    257  *
    258  *  @ingroup memCallback
    259  */
    260 psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func    ///< Function to run
    261                                                 );
     267/** Set callback for problems.
     268 *
     269 *  At various occasions, the memory manager can check the state of the memory
     270 *  stack. If any of these checks discover that the memory stack is corrupted,
     271 *  the psMemProblemCallback is called.
     272 
     273 *  @ingroup memCallback
     274 *
     275 *  @return psMemProblemCallback       old psMemProblemCallback function
     276 */
     277psMemProblemCallback psMemProblemCallbackSet(
     278    psMemProblemCallback func          ///< Function to run at memory problem detection
     279);
     280
     281/** Set callback for out-of-memory.
     282 *
     283 *  If not enough memory is available to satisfy a request by psAlloc or
     284 *  psRealloc, these functions attempt to find an alternative solution by
     285 *  calling the psMemExhaustedCallback, a function which may be set by the
     286 *  programmer in appropriate circumstances, rather than immediately fail.
     287 *  The typical use of such a feature may be when a program needs a large
     288 *  chunk of memory to do an operation, but the exact size is not critical.
     289 *  This feature gives the programmer the opportunity to make a smaller
     290 *  request and try again, limiting the size of the operating buffer.
     291 *
     292 *  @ingroup memCallback
     293 *
     294 *  @return psMemExhaustedCallback     old psMemExhaustedCallback function
     295 */
     296psMemExhaustedCallback psMemExhaustedCallbackSet(
     297    psMemExhaustedCallback func        ///< Function to run at memory exhaustion
     298);
    262299
    263300/** Set call back for when a particular memory block is allocated
    264301 *
    265  *  @ingroup memCallback
    266  */
    267 psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func       ///< Function to run
    268                                               );
     302 *  A private variable, p_psMemAllocateID, can be used to trace the allocation
     303 *  and freeing of specific memory blocks. If p_psMemAllocateID is set and a
     304 *  memory block with that ID is allocated, psMemAllocateCallback is called
     305 *  just before memory is returned to the calling function.
     306 *
     307 *  @ingroup memCallback
     308 *
     309 *  @return psMemAllocateCallback      old psMemAllocateCallback function
     310 */
     311psMemAllocateCallback psMemAllocateCallbackSet(
     312    psMemAllocateCallback func       ///< Function to run at memory allocation of specific mem block
     313);
    269314
    270315/** Set call back for when a particular memory block is freed
    271316 *
    272  *  @ingroup memCallback
    273  */
    274 psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func   ///< Function to run
    275                                       );
     317 *  A private variable, p_psMemFreeID, can be used to trace the freeing of
     318 *  specific memory blocks. If p_psMemFreeID is set and the memory block with
     319 *  the ID is about to be freed, the psMemFreeCallback callback is called just
     320 *  before the memory block is freed.
     321 *
     322 *  @ingroup memCallback
     323 *
     324 *  @return psMemFreeCallback          old psMemFreeCallback function
     325 */
     326psMemFreeCallback psMemFreeCallbackSet(
     327    psMemFreeCallback func             ///< Function to run at memory free of specific mem block
     328);
    276329
    277330/** get next memory ID
    278331 *
    279332 *  @ingroup memCallback
     333 *
     334 *  @return psMemoryId                 the next memory ID to be used
    280335 */
    281336psMemoryId psMemGetId(void);
    282337
    283 /** set p_psMemAllocateID to id
    284  *
    285  *  @ingroup memCallback
    286  */
    287 psMemoryId psMemAllocateCallbackSetID(psMemoryId id     ///< ID to set
    288                                      );
     338/** set p_psMemAllocateID to specific id
     339 *
     340 *  A private variable, p_psMemAllocateID, can be used to trace the allocation
     341 *  and freeing of specific memory blocks. If p_psMemAllocateID is set and a
     342 *  memory block with that ID is allocated, psMemAllocateCallback is called
     343 *  just before memory is returned to the calling function.
     344 *
     345 *  @ingroup memCallback
     346 *
     347 *  @return psMemoryId       
     348 *
     349 *  @see psMemAllocateCallbackSet   
     350 */
     351psMemoryId psMemAllocateCallbackSetID(
     352    psMemoryId id                      ///< ID to set
     353);
    289354
    290355/** set p_psMemFreeID to id
    291356 *
    292  *  @ingroup memCallback
    293  */
    294 psMemoryId psMemFreeCallbackSetID(psMemoryId id ///< ID to set
    295                                  );
     357 *  A private variable, p_psMemFreeID, can be used to trace the freeing of
     358 *  specific memory blocks. If p_psMemFreeID is set and the memory block with
     359 *  the ID is about to be freed, the psMemFreeCallback callback is called just
     360 *  before the memory block is freed.
     361 *
     362 *  @ingroup memCallback
     363 *
     364 *  @return psMemoryId                 the old p_psMemFreeID
     365 *
     366 *  @see psMemFreeCallbackSet
     367 */
     368psMemoryId psMemFreeCallbackSetID(
     369    psMemoryId id                      ///< ID to set
     370);
    296371
    297372//@} End of Memory Management Functions
     
    306381#pragma GCC poison malloc realloc calloc free
    307382#else
    308 #                define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
    309 #                define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
    310 #                define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
    311 #                define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
    312 #            endif
    313 #        endif
    314 
    315 #    endif
     383#define malloc(S)       _Pragma("error Use of malloc is not allowed.  Use psAlloc instead.")
     384#define realloc(P,S)    _Pragma("error Use of realloc is not allowed.  Use psRealloc instead.")
     385#define calloc(S)       _Pragma("error Use of calloc is not allowed.  Use psAlloc instead.")
     386#define free(P)         _Pragma("error Use of free is not allowed.  Use psFree instead.")
     387#endif
     388#endif
     389
     390#endif
    316391// doxygen skip
    317392
Note: See TracChangeset for help on using the changeset viewer.