summaryrefslogtreecommitdiffstats
path: root/libs/utils
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2011-06-15 22:12:32 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-06-15 22:12:32 -0700
commit552bd670071b519d97124621a3c11dc98062c12b (patch)
tree315fd0e01a5311701273eb5552f4f3593d5a6733 /libs/utils
parent85c14352a4f8946a6908eac140936080536fa575 (diff)
parentd5244e0a88ed2f843651aa5ffdc71a45c968e0f3 (diff)
downloadframeworks_base-552bd670071b519d97124621a3c11dc98062c12b.zip
frameworks_base-552bd670071b519d97124621a3c11dc98062c12b.tar.gz
frameworks_base-552bd670071b519d97124621a3c11dc98062c12b.tar.bz2
am d5244e0a: am 52a43990: Revert "revert surfaceflinger leak fix as it uncovered a crasher on xoom"
* commit 'd5244e0a88ed2f843651aa5ffdc71a45c968e0f3': Revert "revert surfaceflinger leak fix as it uncovered a crasher on xoom"
Diffstat (limited to 'libs/utils')
-rw-r--r--libs/utils/RefBase.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp
index 2034486..8db2009 100644
--- a/libs/utils/RefBase.cpp
+++ b/libs/utils/RefBase.cpp
@@ -49,6 +49,11 @@ namespace android {
// ---------------------------------------------------------------------------
+RefBase::Destroyer::~Destroyer() {
+}
+
+// ---------------------------------------------------------------------------
+
class RefBase::weakref_impl : public RefBase::weakref_type
{
public:
@@ -56,7 +61,7 @@ public:
volatile int32_t mWeak;
RefBase* const mBase;
volatile int32_t mFlags;
-
+ Destroyer* mDestroyer;
#if !DEBUG_REFS
@@ -65,6 +70,7 @@ public:
, mWeak(0)
, mBase(base)
, mFlags(0)
+ , mDestroyer(0)
{
}
@@ -357,7 +363,11 @@ 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;
+ if (refs->mDestroyer) {
+ refs->mDestroyer->destroy(this);
+ } else {
+ delete this;
+ }
}
}
refs->decWeak(id);
@@ -390,7 +400,9 @@ int32_t RefBase::getStrongCount() const
return mRefs->mStrong;
}
-
+void RefBase::setDestroyer(RefBase::Destroyer* destroyer) {
+ mRefs->mDestroyer = destroyer;
+}
RefBase* RefBase::weakref_type::refBase() const
{
@@ -414,16 +426,28 @@ void RefBase::weakref_type::decWeak(const void* id)
if (c != 1) return;
if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
- if (impl->mStrong == INITIAL_STRONG_VALUE)
- delete impl->mBase;
- else {
+ if (impl->mStrong == INITIAL_STRONG_VALUE) {
+ if (impl->mBase) {
+ if (impl->mDestroyer) {
+ impl->mDestroyer->destroy(impl->mBase);
+ } else {
+ delete impl->mBase;
+ }
+ }
+ } else {
// LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
delete impl;
}
} else {
impl->mBase->onLastWeakRef(id);
if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
- delete impl->mBase;
+ if (impl->mBase) {
+ if (impl->mDestroyer) {
+ impl->mDestroyer->destroy(impl->mBase);
+ } else {
+ delete impl->mBase;
+ }
+ }
}
}
}
@@ -545,8 +569,10 @@ RefBase::RefBase()
RefBase::~RefBase()
{
- if (mRefs->mWeak == 0) {
- delete mRefs;
+ if ((mRefs->mFlags & OBJECT_LIFETIME_WEAK) == OBJECT_LIFETIME_WEAK) {
+ if (mRefs->mWeak == 0) {
+ delete mRefs;
+ }
}
}