diff options
author | Mathias Agopian <mathias@google.com> | 2011-06-13 14:15:00 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-06-13 14:15:00 -0700 |
commit | 7794b30589786098756e4734794f0cca30109557 (patch) | |
tree | c358eff473b1b9eade46759b3450aa522eb82d46 /libs/utils | |
parent | 574462f9d84a2a7aad0442657167d7e77ebcbef6 (diff) | |
parent | 4c83aefe5938b71555792fc9862c1ee3ea819480 (diff) | |
download | frameworks_native-7794b30589786098756e4734794f0cca30109557.zip frameworks_native-7794b30589786098756e4734794f0cca30109557.tar.gz frameworks_native-7794b30589786098756e4734794f0cca30109557.tar.bz2 |
am 77079399: am a9c9a4ba: fix RefBase so it retains binary-compatibility with gingerbread (DO NOT MERGE)
* commit '77079399fca3e9c71e2ac06f3da26934e1c278b9':
fix RefBase so it retains binary-compatibility with gingerbread (DO NOT MERGE)
Diffstat (limited to 'libs/utils')
-rw-r--r-- | libs/utils/RefBase.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/libs/utils/RefBase.cpp b/libs/utils/RefBase.cpp index 58e0811..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) { } @@ -345,10 +351,6 @@ 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; @@ -361,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) { - destroy(); + if (refs->mDestroyer) { + refs->mDestroyer->destroy(this); + } else { + delete this; + } } } refs->decWeak(id); @@ -394,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 { @@ -420,7 +428,11 @@ void RefBase::weakref_type::decWeak(const void* id) if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) { if (impl->mStrong == INITIAL_STRONG_VALUE) { if (impl->mBase) { - impl->mBase->destroy(); + 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); @@ -430,7 +442,11 @@ void RefBase::weakref_type::decWeak(const void* id) impl->mBase->onLastWeakRef(id); if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) { if (impl->mBase) { - impl->mBase->destroy(); + if (impl->mDestroyer) { + impl->mDestroyer->destroy(impl->mBase); + } else { + delete impl->mBase; + } } } } |