Show
Ignore:
Timestamp:
11/11/07 16:55:53 (1 year ago)
Author:
cneumann
Message:

added: external/internal/weak reference count
changed: wrong directory for ParentPtrWrapper?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Carsten_PtrWork2/Source/System/FieldContainer/Base/OSGAspectStore.inl

    r961 r1014  
    3939OSG_BEGIN_NAMESPACE 
    4040 
    41 /*! \var Int32 AspectStore::_refCount 
    42  *  \brief reference count 
    43  */ 
    44  
    45 /*-------------------------------------------------------------------------*/ 
    46 /*                             Destructor                                  */ 
    47  
    48 inline 
    49 AspectStore::~AspectStore(void) 
    50 
    51 
     41/*-------------------------------------------------------------------------*/ 
     42/* Constructors                                                            */ 
     43 
     44inline 
     45AspectStore::AspectStore(void) : 
     46    _vAspects        ( ), 
     47    _refCount        (0), 
     48    _externalRefCount(0) 
     49
     50    if(_externalRefCountLock == NULL) 
     51    { 
     52        _externalRefCountLock =  
     53            ThreadManager::the()->getLockPool( 
     54                "AspectStore::_externalRefCountLock"); 
     55         
     56        if(_externalRefCountLock != NULL) 
     57        { 
     58            FINFO(("AspectStore::AspectStore: " 
     59                   "Got AspectStore::_externalRefCountLock\n")); 
     60        } 
     61        else 
     62        { 
     63            FFATAL(("AspectStore::AspectStore: " 
     64                    "Failed to get AspectStore::_externalRefCountLock\n")); 
     65        } 
     66    } 
     67     
     68    OSG::addRef(_externalRefCountLock); 
     69
     70 
     71inline 
     72AspectStore::AspectStore(const AspectStore &) : 
     73    _vAspects        ( ), 
     74    _refCount        (0), 
     75    _externalRefCount(0) 
     76
     77    FWARNING(("AspectStore::AspectStore(AspectStore const &) called.\n")); 
     78
     79 
     80/*-------------------------------------------------------------------------*/ 
     81/* Access                                                                  */ 
    5282 
    5383inline 
     
    6494} 
    6595 
    66  
    6796inline 
    6897FieldContainer *AspectStore::getPtr(void) const 
     
    72101 
    73102inline 
    74 void AspectStore::setPtrForAspect(FieldContainerPtr pContainer,  
    75                                   UInt32            uiAspect  ) 
     103void AspectStore::setAspectPtr(FieldContainer *pContainer,  
     104                               UInt32 const    uiAspect  ) 
    76105{ 
    77106    _vAspects.resize(osgMax<UInt32>(_vAspects.size(), uiAspect + 1), NULL); 
     
    81110 
    82111inline 
    83 void AspectStore::removePtrForAspect(UInt32 uiAspect) 
     112void AspectStore::removeAspectPtr(UInt32 const uiAspect) 
    84113{ 
    85114    if(uiAspect >= _vAspects.size()) 
     
    97126} 
    98127 
    99 /*-------------------------------------------------------------------------*/ 
    100 /*                        Reference Counting                               */ 
    101  
    102 inline 
    103 void AspectStore::addRef(void) 
    104 
    105     _refCount++; 
    106 
    107  
    108 inline 
    109 void AspectStore::subRef(void) 
    110 
    111     _refCount--; 
    112  
    113     if(_refCount <= 0) 
    114         delete this; 
    115 
    116  
    117 inline 
    118 Int32 AspectStore::getRefCount(void) 
    119 
    120     return _refCount; 
    121 
    122  
    123 /*-------------------------------------------------------------------------*/ 
    124 /*                            Constructors                                 */ 
    125  
    126 inline 
    127 AspectStore::AspectStore(void) : 
    128     _refCount(0) 
    129 
    130 
    131  
    132 inline 
    133 AspectStore::AspectStore(const AspectStore &) : 
    134     _refCount(0) 
    135 
    136 
    137  
    138 inline 
    139 void AspectStore::fillOffsetArray(AspectOffsetStore &oStore,  
    140                                   FieldContainerPtr  pRef  ) 
     128inline 
     129void AspectStore::fillOffsetArray(AspectOffsetStore &       oStore,  
     130                                  FieldContainer    * const pRef   ) 
    141131{ 
    142132    Char8 *pRefMem = reinterpret_cast<Char8 *>(pRef); 
     
    157147} 
    158148 
     149/*-------------------------------------------------------------------------*/ 
     150/* Reference Counting                                                      */ 
     151 
     152inline 
     153Int32 AspectStore::getRefCount(void) const 
     154{ 
     155    return _refCount; 
     156} 
     157 
     158 
     159inline Int32 
     160AspectStore::getExternalRefCount(void) const 
     161{ 
     162    return _externalRefCount; 
     163} 
     164 
    159165inline 
    160166void AspectStore::dump(void) 
    161167{ 
    162     fprintf(stderr, "RC : %d\n", _refCount); 
     168    fprintf(stderr, "RC : %d ERC : %d\n", _refCount, _externalRefCount); 
    163169 
    164170    for(UInt32 i = 0; i < _vAspects.size(); ++i) 
     
    168174} 
    169175 
    170 inline  
    171 void addRef(const AspectStoreP pObject) 
    172 
    173     if(pObject != NULL) 
    174         pObject->addRef(); 
    175 
    176  
    177 inline 
    178 void subRef(const AspectStoreP pObject) 
    179 
    180     if(pObject != NULL) 
    181         pObject->subRef(); 
    182 
    183  
     176/*-------------------------------------------------------------------------*/ 
     177/* Destructor                                                              */ 
     178 
     179inline 
     180AspectStore::~AspectStore(void) 
     181
     182    OSG::subRef(_externalRefCountLock); 
     183
     184 
     185/*-------------------------------------------------------------------------*/ 
     186/* Reference Counting                                                      */ 
     187 
     188inline void 
     189AspectStore::addReference(void) 
     190
     191    ++_refCount; 
     192
     193 
     194inline void 
     195AspectStore::subReference(void) 
     196
     197    --_refCount; 
     198     
     199    if(_refCount <= 0) 
     200    { 
     201        delete this; 
     202    } 
     203
     204 
     205inline void 
     206AspectStore::acquireExternalReferenceCountLock(void) 
     207
     208    _externalRefCountLock->acquire(this); 
     209
     210 
     211inline void 
     212AspectStore::releaseExternalReferenceCountLock(void) 
     213
     214    _externalRefCountLock->release(this); 
     215
     216 
     217inline void 
     218AspectStore::addExternalReference(void) 
     219
     220    ++_externalRefCount; 
     221
     222 
     223inline void 
     224AspectStore::subExternalReference(void) 
     225
     226    --_externalRefCount; 
     227
     228 
     229/*-------------------------------------------------------------------------*/ 
     230/* Reference Counting Free Functions                                       */ 
     231 
     232inline void 
     233addRef(AspectStore * const objectP) 
     234
     235    if(objectP != NULL) 
     236        objectP->addReference(); 
     237
     238 
     239inline void 
     240subRef(AspectStore * const objectP) 
     241
     242    if(objectP != NULL) 
     243        objectP->subReference(); 
     244
     245  
     246inline Int32 
     247getRefCount(AspectStore * const objectP) 
     248
     249    return objectP->getRefCount(); 
     250
    184251 
    185252OSG_END_NAMESPACE