forked from boostorg/beast
Use destroy() override instead of ContainerDeletePolicy for SharedObject
This commit is contained in:
1 parent
718569d6a1
commit
85ced3dbf7
5 files changed
+26
-40
No files matched your search
@@ -79,20 +79,18 @@ public:
|
||||
The return value indicates if the reference count dropped to zero,
|
||||
so callers who know the derived type can use the ContainerDeletePolicy.
|
||||
*/
|
||||
inline bool decReferenceCount (bool doDelete = true) noexcept
|
||||
void decReferenceCount ()
|
||||
{
|
||||
bassert (getReferenceCount() > 0);
|
||||
if (--refCount == 0)
|
||||
{
|
||||
if (doDelete)
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
destroy ();
|
||||
}
|
||||
|
||||
/** Returns the object's current reference count. */
|
||||
inline int getReferenceCount() const noexcept { return refCount.get(); }
|
||||
inline int getReferenceCount() const noexcept
|
||||
{
|
||||
return refCount.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
@@ -108,6 +106,14 @@ protected:
|
||||
bassert (getReferenceCount() == 0);
|
||||
}
|
||||
|
||||
/** Destroy the object.
|
||||
Derived classes can override this for different behaviors.
|
||||
*/
|
||||
virtual void destroy ()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
/** Resets the reference count to zero without deleting the object.
|
||||
You should probably never need to use this!
|
||||
*/
|
||||
@@ -155,17 +161,11 @@ public:
|
||||
The return value indicates if the reference count dropped to zero,
|
||||
so callers who know the derived type can use the ContainerDeletePolicy.
|
||||
*/
|
||||
inline bool decReferenceCount (bool doDelete = true) noexcept
|
||||
inline void decReferenceCount ()
|
||||
{
|
||||
bassert (getReferenceCount() > 0);
|
||||
if (--refCount == 0)
|
||||
{
|
||||
if (doDelete)
|
||||
delete this;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
destroy ();
|
||||
}
|
||||
|
||||
/** Returns the object's current reference count. */
|
||||
@@ -184,6 +184,11 @@ protected:
|
||||
bassert (getReferenceCount() == 0);
|
||||
}
|
||||
|
||||
virtual void destroy ()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
int refCount;
|
||||
|
||||
@@ -238,8 +238,7 @@ private:
|
||||
static void release (T* t)
|
||||
{
|
||||
if (t != nullptr)
|
||||
if (t->decReferenceCount (false))
|
||||
ContainerDeletePolicy <T>::destroy (t);
|
||||
t->decReferenceCount ();
|
||||
}
|
||||
|
||||
// Swap ownership of the currently referenced object.
|
||||
|
||||
@@ -139,11 +139,10 @@ public:
|
||||
++m_refCount;
|
||||
}
|
||||
|
||||
inline bool decReferenceCount (bool = false) noexcept
|
||||
inline void decReferenceCount () noexcept
|
||||
{
|
||||
if (--m_refCount == 0)
|
||||
destroySingleton ();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Caller must synchronize.
|
||||
|
||||
Reference in new issue
Block a user