summaryrefslogtreecommitdiff
path: root/libs/utils/RefBase.cpp
diff options
context:
space:
mode:
author Simon Wilson <simonwilson@google.com> 2011-05-24 17:29:12 -0700
committer Android Git Automerger <android-git-automerger@android.com> 2011-05-24 17:29:12 -0700
commitb9783b49f4727a0365f2297bb903db8682855adf (patch)
tree0d4831587eed29e6e2366280543ed0f226051807 /libs/utils/RefBase.cpp
parent10b364b4bea8537f955bbbb8b9b40061264b29c9 (diff)
parentc9cd2387b6938a6fbefc731d2177902266f2a130 (diff)
am c9cd2387: Merge changes I37f0f315,I8cbf6044,Ibb598931,I5262bf11 into gingerbread
* commit 'c9cd2387b6938a6fbefc731d2177902266f2a130': Fix a race that could cause GL commands to be executed from the wrong thread. RefBase subclasses can now decide how they want to be destroyed. Fix a race in SurfaceFlinger that could cause layers to be leaked forever. Fix a race-condtion in SurfaceFlinger that could lead to a crash.
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 d28b751a47f3..3c560ae68ec0 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();
}
}
}