diff --git a/base/include/refbase.h b/base/include/refbase.h index a49bfccf8ab7a829579e648371c73f4423f84484..a35b026e6420ad38e682cf0848dcf2da40072fc9 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 3b71cf708223be1349045b6987ac339e59e9d6ed..1a1f26cf6e4f4c4e48d382f68bc3cafe3451d6d5 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -319,6 +319,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); @@ -498,6 +503,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); }