From 710bb7fc8899edfaac1b1ea782c96acc392c132c Mon Sep 17 00:00:00 2001 From: wujianlin Date: Tue, 24 Oct 2023 18:18:23 +0800 Subject: [PATCH 1/2] Reduce the repetition rate of RefBase code and increase event_demultiplexer debugging printing Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/I8AKVV?from=project-issue Signed-off-by: wujianlin --- base/src/event_demultiplexer.cpp | 2 +- base/src/refbase.cpp | 39 ++++++++------------------------ 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/base/src/event_demultiplexer.cpp b/base/src/event_demultiplexer.cpp index 765b743..9e1633b 100644 --- a/base/src/event_demultiplexer.cpp +++ b/base/src/event_demultiplexer.cpp @@ -111,7 +111,7 @@ void EventDemultiplexer::Polling(int timeout /* ms */) return; } if (nfds == -1) { - UTILS_LOGE("epoll_wait failed."); + UTILS_LOGE("epoll_wait failed, errno %{public}d", errno); return; } diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index ec96997..30f64b5 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -211,7 +211,7 @@ RefCounter::~RefCounter() #endif } -int RefCounter::IncStrongRefCount(const void* objectId) +void RefCounter::DebugRefBase() { #ifdef DEBUG_REFBASE if (enableTrack) { @@ -221,7 +221,12 @@ int RefCounter::IncStrongRefCount(const void* objectId) GetNewTrace(objectId); #endif } -#endif +#endif +} + +int RefCounter::IncStrongRefCount(const void* objectId) +{ + DebugRefBase(); int curCount = atomicStrong_.load(std::memory_order_relaxed); if (curCount >= 0) { curCount = atomicStrong_.fetch_add(1, std::memory_order_relaxed); @@ -235,15 +240,7 @@ int RefCounter::IncStrongRefCount(const void* objectId) int RefCounter::DecStrongRefCount(const void* objectId) { -#ifdef DEBUG_REFBASE - if (enableTrack) { -#ifdef PRINT_TRACK_AT_ONCE - PrintRefs(objectId); -#else - GetNewTrace(objectId); -#endif - } -#endif + DebugRefBase(); int curCount = GetStrongRefCount(); if (curCount == INITIAL_PRIMARY_VALUE) { // unexpected case: there had never a strong reference. @@ -264,29 +261,13 @@ int RefCounter::GetStrongRefCount() int RefCounter::IncWeakRefCount(const void* objectId) { -#ifdef DEBUG_REFBASE - if (enableTrack) { -#ifdef PRINT_TRACK_AT_ONCE - PrintRefs(objectId); -#else - GetNewTrace(objectId); -#endif - } -#endif + DebugRefBase(); return atomicWeak_.fetch_add(1, std::memory_order_relaxed); } int RefCounter::DecWeakRefCount(const void* objectId) { -#ifdef DEBUG_REFBASE - if (enableTrack) { -#ifdef PRINT_TRACK_AT_ONCE - PrintRefs(objectId); -#else - GetNewTrace(objectId); -#endif - } -#endif + DebugRefBase(); int curCount = GetWeakRefCount(); if (curCount > 0) { curCount = atomicWeak_.fetch_sub(1, std::memory_order_release); -- Gitee From 519d68edc1d4e99ca650dfbb17d63e7b62633fd2 Mon Sep 17 00:00:00 2001 From: wujianlin Date: Wed, 25 Oct 2023 14:37:13 +0800 Subject: [PATCH 2/2] Reduce the repetition rate of RefBase code and increase event_demultiplexer debugging printing Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/I8AKVV?from=project-issue Signed-off-by: wujianlin --- base/src/refbase.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index 30f64b5..affddd9 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -21,6 +21,19 @@ 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) { @@ -211,19 +224,6 @@ RefCounter::~RefCounter() #endif } -void RefCounter::DebugRefBase() -{ -#ifdef DEBUG_REFBASE - if (enableTrack) { -#ifdef PRINT_TRACK_AT_ONCE - PrintRefs(objectId); -#else - GetNewTrace(objectId); -#endif - } -#endif -} - int RefCounter::IncStrongRefCount(const void* objectId) { DebugRefBase(); -- Gitee