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
142 Referenced&
operator = (
const Referenced& ) {
return *
this; }
144 LUNCHBOX_API
virtual void notifyFree();
148 bool _hasBeenDeleted;
150 #ifdef LUNCHBOX_REFERENCED_DEBUG 172 #endif //LUNCHBOX_REFERENCED_H std::ostream & enableFlush(std::ostream &os)
Re-enable flushing of the Log stream.
Defines export visibility macros for library Lunchbox.
bool unref(const void *holder=0) const
Decrease the reference count.
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.
std::ostream & disableHeader(std::ostream &os)
Disable printing of the Log header for subsequent lines.
void ref(const void *holder=0) const
Increase the reference count.
std::string backtrace(const size_t skipFrames)
Get the current call stack.
Base class for referenced objects.
Abstraction layer and common utilities for multi-threaded programming.
Referenced & operator=(const Referenced &)
Assign another object to this object.
virtual ~Referenced()
Destruct a reference-counted object.
static Log & instance()
The per-thread logger.
Referenced()
Construct a new reference-counted object.
int64_t getTime64() const
Referenced(const Referenced &)
Construct a new copy of a reference-counted object.
int32_t getRefCount() const
std::ostream & disableFlush(std::ostream &os)
Disable flushing of the Log stream.