diff --git a/base/include/refbase.h b/base/include/refbase.h index 0a3a86f040736b15caa9d4b9b1d90e36f0634e53..1134be4c8c6e67f8cada98941d9336c32d53b86f 100644 --- a/base/include/refbase.h +++ b/base/include/refbase.h @@ -243,6 +243,8 @@ public: #endif private: + void DebugRefBase(const void *objectId); + std::atomic atomicStrong_; // = (num of sptr) or Initial-value std::atomic atomicWeak_; // = (num of sptr)+(num of WeakRefCounter) std::atomic atomicRefCount_; // = (num of WeakRefCounter) + 1 diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index affddd942903cd1020d948dca3b24427740820c1..b9db296d3aeb6ee036cf9d90e5191bcbfe10164e 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -21,19 +21,6 @@ namespace OHOS { -void DebugRefBase() -{ -#ifdef DEBUG_REFBASE - if (enableTrack) { -#ifdef PRINT_TRACK_AT_ONCE - PrintRefs(objectId); -#else - GetNewTrace(objectId); -#endif - } -#endif -} - WeakRefCounter::WeakRefCounter(RefCounter *counter, void *cookie) : atomicWeak_(0), refCounter_(counter), cookie_(cookie) { @@ -172,6 +159,19 @@ void RefCounter::EnableTracker() #endif #endif +void RefCounter::DebugRefBase([[maybe_unused]]const void* objectId) +{ +#ifdef DEBUG_REFBASE + if (enableTrack) { +#ifdef PRINT_TRACK_AT_ONCE + PrintRefs(objectId); +#else + GetNewTrace(objectId); +#endif + } +#endif +} + RefCounter::RefCounter() : atomicStrong_(INITIAL_PRIMARY_VALUE), atomicWeak_(0), atomicRefCount_(0), atomicFlags_(0), atomicAttempt_(0) { @@ -226,7 +226,7 @@ RefCounter::~RefCounter() int RefCounter::IncStrongRefCount(const void* objectId) { - DebugRefBase(); + DebugRefBase(objectId); int curCount = atomicStrong_.load(std::memory_order_relaxed); if (curCount >= 0) { curCount = atomicStrong_.fetch_add(1, std::memory_order_relaxed); @@ -240,7 +240,7 @@ int RefCounter::IncStrongRefCount(const void* objectId) int RefCounter::DecStrongRefCount(const void* objectId) { - DebugRefBase(); + DebugRefBase(objectId); int curCount = GetStrongRefCount(); if (curCount == INITIAL_PRIMARY_VALUE) { // unexpected case: there had never a strong reference. @@ -261,13 +261,13 @@ int RefCounter::GetStrongRefCount() int RefCounter::IncWeakRefCount(const void* objectId) { - DebugRefBase(); + DebugRefBase(objectId); return atomicWeak_.fetch_add(1, std::memory_order_relaxed); } int RefCounter::DecWeakRefCount(const void* objectId) { - DebugRefBase(); + DebugRefBase(objectId); int curCount = GetWeakRefCount(); if (curCount > 0) { curCount = atomicWeak_.fetch_sub(1, std::memory_order_release);