IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 803


Ignore:
Timestamp:
May 27, 2004, 5:17:39 PM (22 years ago)
Author:
desonia
Message:

added mutex for memid.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

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

    r648 r803  
    88 *  @author Robert Lupton, Princeton University
    99 *
    10  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-05-12 19:05:02 $
     10 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-05-28 03:17:39 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3131static psMemBlock *lastMemBlockAllocated = NULL;
    3232pthread_mutex_t   memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     33pthread_mutex_t   memIdMutex = PTHREAD_MUTEX_INITIALIZER;
    3334
    3435/**
     
    172173psMemoryId psMemGetId(void)
    173174{
    174     return memid + 1;
     175    psMemoryId id;
     176    pthread_mutex_lock(&memIdMutex);
     177    id = memid + 1;
     178    pthread_mutex_unlock(&memIdMutex);
     179
     180    return id;
    175181}
    176182
     
    252258    }
    253259
     260
     261    // increment the memory id safely.
     262    pthread_mutex_lock(&memBlockListMutex);
    254263    *(psMemoryId*)&ptr->id = ++memid;
     264    pthread_mutex_unlock(&memBlockListMutex);
     265
    255266    ptr->file = file;
    256267    *(unsigned int*)&ptr->lineno = lineno;
     
    260271    ptr->userMemorySize = size;
    261272    *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
     273    ptr->previousBlock = NULL;
    262274
    263275    // need exclusive access of the memory block list now...
     
    265277
    266278    // insert the new block to the front of the memBlock linked-list
    267     ptr->previousBlock = NULL;
    268279    ptr->nextBlock = lastMemBlockAllocated;
    269280    if (ptr->nextBlock != NULL) {
  • trunk/psLib/src/sys/psMemory.h

    r768 r803  
    1212 *  @author Robert Lupton, Princeton University
    1313 *
    14  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-05-24 23:03:51 $
     14 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-05-28 03:17:39 $
    1616 *
    1717 *  @ingroup SystemGroup System Utilities
     
    6464    const char* file;                   ///< set from __FILE__ in e.g. p_psAlloc
    6565    const int lineno;                   ///< set from __LINE__ in e.g. p_psAlloc
    66     psReferenceCount refCounter;            ///< how many times pointer is referenced
     66    // TODO: refCounter should be mutexed?
     67    psReferenceCount refCounter;        ///< how many times pointer is referenced
    6768    const void* endblock;               ///< initialised to p_psMEMMAGIC
    6869}
  • trunk/psLib/src/sysUtils/psMemory.c

    r648 r803  
    88 *  @author Robert Lupton, Princeton University
    99 *
    10  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-05-12 19:05:02 $
     10 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-05-28 03:17:39 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3131static psMemBlock *lastMemBlockAllocated = NULL;
    3232pthread_mutex_t   memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     33pthread_mutex_t   memIdMutex = PTHREAD_MUTEX_INITIALIZER;
    3334
    3435/**
     
    172173psMemoryId psMemGetId(void)
    173174{
    174     return memid + 1;
     175    psMemoryId id;
     176    pthread_mutex_lock(&memIdMutex);
     177    id = memid + 1;
     178    pthread_mutex_unlock(&memIdMutex);
     179
     180    return id;
    175181}
    176182
     
    252258    }
    253259
     260
     261    // increment the memory id safely.
     262    pthread_mutex_lock(&memBlockListMutex);
    254263    *(psMemoryId*)&ptr->id = ++memid;
     264    pthread_mutex_unlock(&memBlockListMutex);
     265
    255266    ptr->file = file;
    256267    *(unsigned int*)&ptr->lineno = lineno;
     
    260271    ptr->userMemorySize = size;
    261272    *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
     273    ptr->previousBlock = NULL;
    262274
    263275    // need exclusive access of the memory block list now...
     
    265277
    266278    // insert the new block to the front of the memBlock linked-list
    267     ptr->previousBlock = NULL;
    268279    ptr->nextBlock = lastMemBlockAllocated;
    269280    if (ptr->nextBlock != NULL) {
  • trunk/psLib/src/sysUtils/psMemory.h

    r768 r803  
    1212 *  @author Robert Lupton, Princeton University
    1313 *
    14  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-05-24 23:03:51 $
     14 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-05-28 03:17:39 $
    1616 *
    1717 *  @ingroup SystemGroup System Utilities
     
    6464    const char* file;                   ///< set from __FILE__ in e.g. p_psAlloc
    6565    const int lineno;                   ///< set from __LINE__ in e.g. p_psAlloc
    66     psReferenceCount refCounter;            ///< how many times pointer is referenced
     66    // TODO: refCounter should be mutexed?
     67    psReferenceCount refCounter;        ///< how many times pointer is referenced
    6768    const void* endblock;               ///< initialised to p_psMEMMAGIC
    6869}
Note: See TracChangeset for help on using the changeset viewer.