summaryrefslogtreecommitdiff
path: root/libutils/RefBase.cpp
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2021-04-08 04:26:32 +0000
committerScott Lobdell <slobdell@google.com>2021-04-08 04:26:32 +0000
commit89dd0c0c1d2d070282e44d5f964da36ccb0567d4 (patch)
tree82d17e3c6c8709d69f82a4b362a528113b910e2f /libutils/RefBase.cpp
parent8d5890fc719a157df1cbf4e39a551ff93fca91b2 (diff)
parent98be3062a46117738128efcd4b219f9f3f94ec47 (diff)
Merge SP1A.210407.002
Change-Id: I5fc9b14634cd9f2991dc43b2dedb514603d138a1
Diffstat (limited to 'libutils/RefBase.cpp')
-rw-r--r--libutils/RefBase.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index 98d0963b8..9d359b805 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)
{