18 #ifndef LUNCHBOX_REFERENCED_H
19 #define LUNCHBOX_REFERENCED_H
22 #include <lunchbox/atomic.h>
23 #include <lunchbox/debug.h>
26 #ifdef LUNCHBOX_REFERENCED_DEBUG
27 # include <lunchbox/clock.h>
28 # include <lunchbox/hash.h>
29 # include <lunchbox/lockable.h>
30 # include <lunchbox/scopedMutex.h>
31 # include <lunchbox/spinLock.h>
49 #ifdef LUNCHBOX_REFERENCED_DEBUG
50 void ref(
const void* holder = 0 )
const
52 void ref (
const void* = 0 ) const
56 LBASSERT( !_hasBeenDeleted );
60 #ifdef LUNCHBOX_REFERENCED_DEBUG
68 HolderHash::iterator i = _holders->find( holder );
69 LBASSERTINFO( i == _holders->end(), i->second );
70 _holders.data[ holder ] = cs.str();
82 #ifdef LUNCHBOX_REFERENCED_DEBUG
83 bool unref(
const void* holder = 0 ) const
85 bool unref (
const void* = 0 ) const
89 LBASSERT( !_hasBeenDeleted );
91 LBASSERT( _refCount > 0 );
92 const bool last = (--_refCount==0);
94 #ifdef LUNCHBOX_REFERENCED_DEBUG
98 HolderHash::iterator i = _holders->find( holder );
99 LBASSERT( i != _holders->end( ));
100 _holders->erase( i );
101 LBASSERT( _holders->find( holder ) == _holders->end( ));
106 const_cast< Referenced*
>( this )->notifyFree();
114 #ifdef LUNCHBOX_REFERENCED_DEBUG
115 void printHolders( std::ostream& os )
const
120 for( HolderHash::const_iterator i = _holders->begin();
121 i != _holders->end(); ++i )
123 os <<
"Holder " << i->first <<
": " << i->second
130 void printHolders( std::ostream& )
const {}
137 , _hasBeenDeleted( false )
143 , _hasBeenDeleted( false )
149 LBASSERT( !_hasBeenDeleted );
150 _hasBeenDeleted =
true;
151 LBASSERTINFO( _refCount == 0,
152 "Deleting object with ref count " << _refCount );
158 LUNCHBOX_API
virtual void notifyFree();
162 bool _hasBeenDeleted;
164 #ifdef LUNCHBOX_REFERENCED_DEBUG
186 #endif //LUNCHBOX_REFERENCED_H