summaryrefslogtreecommitdiff
path: root/libs/utils/RefBase.cpp
diff options
context:
space:
mode:
author Mathias Agopian <mathias@google.com> 2011-05-19 18:03:31 -0700
committer Mathias Agopian <mathias@google.com> 2011-05-23 16:13:48 -0700
commit9e7636681eda094dd328ce9bf54d0b0166be1e67 (patch)
treedaa994e6a3ed671ec6e09e31a8408bd7d6240871 /libs/utils/RefBase.cpp
parentfa21cb2e58838761157d3ee929a77e23b602bd01 (diff)
RefBase subclasses can now decide how they want to be destroyed.
This adds a destroy() virtual on RefBase which sublasses can implement. destroy() is called in lieu of the destructor whenthe last strong ref goes away. Bug: 4483050 Change-Id: I8cbf6044a6fd3f01043a45592b5a60fa1e5fade2
Diffstat (limited to 'libs/utils/RefBase.cpp')
-rw-r--r--libs/utils/RefBase.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp
index 0bd1af4ebf18..c68e32a0df2f 100644
--- a/libs/utils/RefBase.cpp
+++ b/libs/utils/RefBase.cpp
@@ -298,6 +298,10 @@ void RefBase::incStrong(const void* id) const
const_cast<RefBase*>(this)->onFirstRef();
}
+void RefBase::destroy() const {
+ delete this;
+}
+
void RefBase::decStrong(const void* id) const
{
weakref_impl* const refs = mRefs;
@@ -310,7 +314,7 @@ void RefBase::decStrong(const void* id) const
if (c == 1) {
const_cast<RefBase*>(this)->onLastStrongRef(id);
if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
- delete this;
+ destroy();
}
}
refs->removeWeakRef(id);
@@ -370,7 +374,8 @@ void RefBase::weakref_type::decWeak(const void* id)
if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
if (impl->mStrong == INITIAL_STRONG_VALUE)
- delete impl->mBase;
+ if (impl->mBase)
+ impl->mBase->destroy();
else {
// LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
delete impl;
@@ -378,7 +383,8 @@ void RefBase::weakref_type::decWeak(const void* id)
} else {
impl->mBase->onLastWeakRef(id);
if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
- delete impl->mBase;
+ if (impl->mBase)
+ impl->mBase->destroy();
}
}
}