From 164cb8216c27f65185d353d8b283635dc5944c2d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 23 Feb 2005 12:50:10 +0000 Subject: [PATCH] Made Referenced::ref() and unref() inline methods. --- include/osg/Referenced | 42 ++++++++++++++++++++++++++++++++++++++++-- src/osg/Referenced.cpp | 4 ++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/osg/Referenced b/include/osg/Referenced index a83fa28aa..bd254d228 100644 --- a/include/osg/Referenced +++ b/include/osg/Referenced @@ -25,6 +25,7 @@ #ifdef OSG_JAVA_BUILD #include #else +#include #include #endif @@ -55,13 +56,13 @@ class SG_EXPORT Referenced /** Increment the reference count by one, indicating that this object has another pointer which is referencing it.*/ - void ref() const; + inline void ref() const; /** Decrement the reference count by one, indicating that a pointer to this object is referencing it. If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.*/ - void unref() const; + inline void unref() const; /** Decrement the reference count by one, indicating that a pointer to this object is referencing it. However, do @@ -127,6 +128,43 @@ class DeleteHandler * The default implementation does a delete straight away.*/ virtual void requestDelete(const Referenced* object) { doDelete(object); } }; + +inline void Referenced::ref() const +{ + if (_refMutex) + { + OpenThreads::ScopedLock lock(*_refMutex); + ++_refCount; + } + else + { + ++_refCount; + } +} + +inline void Referenced::unref() const +{ + bool needDelete = false; + if (_refMutex) + { + OpenThreads::ScopedLock lock(*_refMutex); + --_refCount; + needDelete = _refCount<=0; + } + else + { + --_refCount; + needDelete = _refCount<=0; + } + + if (needDelete) + { + if (getDeleteHandler()) getDeleteHandler()->requestDelete(this); + else delete this; + } +} + + #else /** Java wrappers use the CBridgable base-class for referencing * and garbage collection. diff --git a/src/osg/Referenced.cpp b/src/osg/Referenced.cpp index be48160ce..309ad8e15 100644 --- a/src/osg/Referenced.cpp +++ b/src/osg/Referenced.cpp @@ -100,7 +100,7 @@ void Referenced::setThreadSafeRefUnref(bool threadSafe) } } - +/* void Referenced::ref() const { if (_refMutex) @@ -136,7 +136,7 @@ void Referenced::unref() const else delete this; } } - +*/ void Referenced::unref_nodelete() const { if (_refMutex)