diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-06 01:09:33 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-06 01:09:33 +0000 |
commit | b70d87b64c19e1136b9dbe6dbfa84a6c58cc4626 (patch) | |
tree | 033746cc03862190c49d73933901a96824acb7c9 /libutils/RefBase.cpp | |
parent | 2e6a2488799141dcd6140424d4c067c4e3f43b07 (diff) | |
parent | 746757a02ff2a7409741cd04abd9c338eb119dda (diff) |
Snap for 7259849 from 746757a02ff2a7409741cd04abd9c338eb119dda to sc-release
Change-Id: I8bba0cb33f16213431fe653597ce9ba5ec72cee2
Diffstat (limited to 'libutils/RefBase.cpp')
-rw-r--r-- | libutils/RefBase.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp index 8e45226c5..b57e28741 100644 --- a/libutils/RefBase.cpp +++ b/libutils/RefBase.cpp @@ -443,6 +443,20 @@ void RefBase::incStrong(const void* id) const refs->mBase->onFirstRef(); } +void RefBase::incStrongRequireStrong(const void* id) const { + weakref_impl* const refs = mRefs; + refs->incWeak(id); + + refs->addStrongRef(id); + const int32_t c = refs->mStrong.fetch_add(1, std::memory_order_relaxed); + + LOG_ALWAYS_FATAL_IF(c <= 0 || c == INITIAL_STRONG_VALUE, + "incStrongRequireStrong() called on %p which isn't already owned", refs); +#if PRINT_REFS + ALOGD("incStrong (requiring strong) of %p from %p: cnt=%d\n", this, id, c); +#endif +} + void RefBase::decStrong(const void* id) const { weakref_impl* const refs = mRefs; @@ -521,6 +535,14 @@ void RefBase::weakref_type::incWeak(const void* id) ALOG_ASSERT(c >= 0, "incWeak called on %p after last weak ref", this); } +void RefBase::weakref_type::incWeakRequireWeak(const void* id) +{ + weakref_impl* const impl = static_cast<weakref_impl*>(this); + impl->addWeakRef(id); + const int32_t c __unused = impl->mWeak.fetch_add(1, + std::memory_order_relaxed); + LOG_ALWAYS_FATAL_IF(c <= 0, "incWeakRequireWeak called on %p which has no weak refs", this); +} void RefBase::weakref_type::decWeak(const void* id) { |