Added a DeleteHandler into osg::Referenced so that it can delete objects

via a seperate delete handler.  Useful for making unref()/ref() thread safe if
the users needs to address this issue.
This commit is contained in:
Robert Osfield
2002-12-16 10:25:31 +00:00
parent cb87e7b3bc
commit 884b2730e8
5 changed files with 96 additions and 22 deletions

38
src/osg/Referenced.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include <osg/Referenced>
#include <osg/Notify>
#include <typeinfo>
namespace osg
{
static std::auto_ptr<DeleteHandler> s_deleteHandler(0);
void Referenced::setDeleteHandler(DeleteHandler* handler)
{
s_deleteHandler.reset(handler);
}
DeleteHandler* Referenced::getDeleteHandler()
{
return s_deleteHandler.get();
}
#ifdef OSG_COMPILE_UNIT_TESTS
int Referenced::_createdCount = 0;
int Referenced::_deletedCount = 0;
#endif
Referenced::~Referenced()
{
if (_refCount>0)
{
notify(WARN)<<"Warning: deleting still referenced object "<<this<<" of type '"<<typeid(this).name()<<"'"<<std::endl;
notify(WARN)<<" the final reference count was "<<_refCount<<", memory corruption possible."<<std::endl;
}
#ifdef OSG_COMPILE_UNIT_TESTS
_deletedCount ++;
#endif
}
}; // end of namespace osg