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 void ref(
const void* holder LB_UNUSED = 0 )
const
52 LBASSERT( !_hasBeenDeleted );
56 #ifdef LUNCHBOX_REFERENCED_DEBUG
64 HolderHash::iterator i = _holders->find( holder );
65 LBASSERTINFO( i == _holders->end(), i->second );
66 _holders.data[ holder ] = cs.str();
78 bool unref(
const void* holder LB_UNUSED = 0 )
const
81 LBASSERT( !_hasBeenDeleted );
83 LBASSERT( _refCount > 0 );
84 const bool last = (--_refCount==0);
86 #ifdef LUNCHBOX_REFERENCED_DEBUG
90 HolderHash::iterator i = _holders->find( holder );
91 LBASSERT( i != _holders->end( ));
93 LBASSERT( _holders->find( holder ) == _holders->end( ));
98 const_cast< Referenced*
>( this )->notifyFree();
106 #ifdef LUNCHBOX_REFERENCED_DEBUG
107 void printHolders( std::ostream& os )
const
112 for( HolderHash::const_iterator i = _holders->begin();
113 i != _holders->end(); ++i )
115 os <<
"Holder " << i->first <<
": " << i->second << std::endl;
121 void printHolders( std::ostream& )
const {}
131 , _hasBeenDeleted( false )
132 #ifdef LUNCHBOX_REFERENCED_DEBUG
144 LUNCHBOX_API
virtual void notifyFree();
148 bool _hasBeenDeleted;
150 #ifdef LUNCHBOX_REFERENCED_DEBUG
172 #endif //LUNCHBOX_REFERENCED_H
Defines export visibility macros for Lunchbox.
LUNCHBOX_API Referenced()
Construct a new reference-counted object.
LUNCHBOX_API std::string backtrace(const size_t skipFrames)
Get the current call stack.
LUNCHBOX_API int64_t getTime64() const
LUNCHBOX_API std::ostream & enableFlush(std::ostream &os)
Re-enable flushing of the Log stream.
LUNCHBOX_API std::ostream & disableHeader(std::ostream &os)
Disable printing of the Log header for subsequent lines.
LUNCHBOX_API std::ostream & enableHeader(std::ostream &os)
Re-enable printing of the Log header.
A convenience structure to hold data together with a lock for access.
virtual LUNCHBOX_API ~Referenced()
Destruct a reference-counted object.
void ref(const void *holder LB_UNUSED=0) const
Increase the reference count.
bool unref(const void *holder LB_UNUSED=0) const
Decrease the reference count.
Base class for referenced objects.
static LUNCHBOX_API Log & instance()
The per-thread logger.
Referenced & operator=(const Referenced &)
Assign another object to this object.
LUNCHBOX_API std::ostream & disableFlush(std::ostream &os)
Disable flushing of the Log stream.
Referenced(const Referenced &)
Construct a new copy of a reference-counted object.
int32_t getRefCount() const