From 08eda219aa7b8a5c49d8dd955fee810d89925bc4 Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Wed, 21 Feb 2024 15:50:47 +0800 Subject: [PATCH] Fix compilation fail while enabling RefTracker Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/I92NDY?from=project-issue Signed-off-by: chenkeyu --- base/include/refbase.h | 2 ++ base/src/refbase.cpp | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/base/include/refbase.h b/base/include/refbase.h index 0a3a86f..1134be4 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 affddd9..b9db296 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); -- Gitee