diff --git a/base/include/refbase.h b/base/include/refbase.h index 1134be4c8c6e67f8cada98941d9336c32d53b86f..9537d9d56de82c0ce4655075b990d0246280e364 100644 --- a/base/include/refbase.h +++ b/base/include/refbase.h @@ -184,6 +184,11 @@ public: */ void SetAttemptAcquire(); + /** + * @brief Get the current times of attempts. + */ + int GetAttemptAcquire(); + /** * @brief Check if the number of attempts is greater than 0. * diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index b9db296d3aeb6ee036cf9d90e5191bcbfe10164e..ec6d08ad259e4a19708a138b3e7d1565a22500f7 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -302,6 +302,11 @@ int RefCounter::GetWeakRefCount() return atomicWeak_.load(std::memory_order_relaxed); } +int RefCounter::GetAttemptAcquire() +{ + return atomicAttempt_.load(std::memory_order_relaxed); +} + void RefCounter::SetAttemptAcquire() { (void)atomicAttempt_.fetch_add(1, std::memory_order_relaxed); @@ -484,6 +489,11 @@ void RefBase::IncStrongRef(const void *objectId) } if (refs_->IsAttemptAcquireSet()) { refs_->ClearAttemptAcquire(); + const int attemptCount = refs_->GetAttemptAcquire(); + if (attemptCount < 0) { + UTILS_LOGF("Multi-threads trigger illegal decstrong from %{public}d due to AttemptIncStrong in ipc", + attemptCount); + } refs_->DecStrongRefCount(objectId); refs_->DecWeakRefCount(objectId); }