IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5216 for trunk/psLib/src/sys


Ignore:
Timestamp:
Sep 30, 2005, 4:22:26 PM (21 years ago)
Author:
desonia
Message:

changed psArrayGet/psArraySet/psArrayRemove to do proper reference counting.

Location:
trunk/psLib/src/sys
Files:
2 edited

Legend:

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

    r4971 r5216  
    88*  @author Robert Lupton, Princeton University
    99*
    10 *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2005-09-08 00:17:26 $
     10*  @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2005-10-01 02:22:13 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    583583}
    584584
     585psPtr p_psMemSetRefCounter(
     586    psPtr vptr,
     587    psReferenceCount count,
     588    const char *file,
     589    psS32 lineno)
     590{
     591    psMemBlock* ptr;
     592
     593    if (vptr == NULL) {
     594        return vptr;
     595    }
     596
     597    if (count < 0) {
     598        count = 0;
     599    }
     600
     601    ptr = ((psMemBlock* ) vptr) - 1;
     602
     603    if (checkMemBlock(ptr, __func__)) {
     604        memProblemCallback(ptr, file, lineno);
     605    }
     606
     607    pthread_mutex_lock(&ptr->refCounterMutex);
     608    ptr->refCounter = count;
     609    pthread_mutex_unlock(&ptr->refCounterMutex);
     610
     611    if (count < 1) {
     612        vptr = p_psMemDecrRefCounter(vptr,file,lineno);
     613    }
     614
     615    return vptr;
     616}
     617
    585618// decrement and return refCounter
    586619psPtr p_psMemDecrRefCounter(psPtr vptr,
     
    707740    return PTR->freeFunc;
    708741}
    709 
    710742
    711743bool psMemCheckType(psDataType type,
  • trunk/psLib/src/sys/psMemory.h

    r4920 r5216  
    1212 *  @ingroup MemoryManagement
    1313 *
    14  *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-08-31 02:07:11 $
     14 *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-10-01 02:22:13 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    350350#endif // !DOXYGEN
    351351
     352/** Set reference counter and return the pointer
     353 *
     354 *  @ingroup memRefCount
     355 *
     356 *  @return psPtr    the pointer with refCount set, or NULL if pointer is
     357 *                   fully dereferenced.
     358 */
     359#ifdef DOXYGEN
     360psPtr psMemSetRefCounter(
     361    psPtr ptr,                        ///< Pointer to decrement refCounter, and return
     362    psReferenceCount count            ///< New reference count
     363);
     364#else // DOXYGEN
     365psPtr p_psMemSetRefCounter(
     366    psPtr vptr,                        ///< Pointer to decrement refCounter, and return
     367    psReferenceCount count,            ///< New reference count
     368    const char *file,                  ///< File of call
     369    psS32 lineno                       ///< Line number of call
     370);
     371
     372#ifndef SWIG
     373#define psMemSetRefCounter(vptr, count) p_psMemSetRefCounter(vptr, count, __FILE__, __LINE__)
     374#endif // !SWIG
     375
     376#endif // !DOXYGEN
     377
    352378/** Set callback for problems.
    353379 *
Note: See TracChangeset for help on using the changeset viewer.