From 5501ea4bf8848ada49605502b81b9ac458ea5e4f Mon Sep 17 00:00:00 2001 From: xingzeng Date: Fri, 12 Sep 2025 10:47:24 +0800 Subject: [PATCH] Remove compile condition OHOS_PLATFORM Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/ICXL1H Reason Remove compile condition OHOS_PLATFORM Value Remove compile condition OHOS_PLATFORM Signed-off-by: xingzeng --- base/include/refbase.h | 6 ------ base/src/refbase.cpp | 12 ------------ base/test/unittest/common/utils_refbase_test.cpp | 2 -- 3 files changed, 20 deletions(-) diff --git a/base/include/refbase.h b/base/include/refbase.h index 68fb082..cee9a69 100644 --- a/base/include/refbase.h +++ b/base/include/refbase.h @@ -240,7 +240,6 @@ public: */ void ExtendObjectLifetime(); -#ifdef OHOS_PLATFORM using CanPromote = std::function; void SetCanPromote(const CanPromote& canPromote); @@ -248,7 +247,6 @@ public: void RemoveCanPromote(); bool IsCanPromoteValid(); -#endif #if ((defined DEBUG_REFBASE) && (!defined TRACK_ALL)) /** @@ -277,9 +275,7 @@ private: std::atomic atomicAttempt_; // Number of attempts RefPtrCallback callback_ = nullptr; // Callback function to deallocate the corresponding RefBase object static constexpr unsigned int FLAG_EXTEND_LIFE_TIME = 0x00000002; // Extended life-time bit to be set via logic-OR -#ifdef OHOS_PLATFORM CanPromote canPromote_ = nullptr; -#endif #ifdef DEBUG_REFBASE #ifdef TRACK_ALL bool enableTrack = true; @@ -611,9 +607,7 @@ public: */ void EnableTrackerWithDomainId(unsigned int domainId); -#ifdef OHOS_PLATFORM virtual bool CanPromote(); -#endif private: RefCounter *refs_ = nullptr; // Pointer to the corresponding reference diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index 37eba34..60e26d3 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -230,7 +230,6 @@ bool RefCounter::IsRefPtrValid() return callback_ != nullptr; } -#ifdef OHOS_PLATFORM void RefCounter::SetCanPromote(const CanPromote &canPromote) { canPromote_ = canPromote; @@ -245,7 +244,6 @@ bool RefCounter::IsCanPromoteValid() { return canPromote_ != nullptr; } -#endif RefCounter::~RefCounter() { @@ -421,11 +419,9 @@ bool RefCounter::AttemptIncStrongRef(const void *objectId, int &outCount) } if (IsLifeTimeExtended()) { -#ifdef OHOS_PLATFORM if (!IsCanPromoteValid() || !canPromote_()) { return false; } -#endif curCount = atomicStrong_.fetch_add(1, std::memory_order_relaxed); RefBaseDebugPrint(curCount, __builtin_return_address(0), objectId, "++", "atomicStrong_"); } @@ -474,9 +470,7 @@ RefBase::RefBase() : refs_(new RefCounter()) { refs_->IncRefCount(); refs_->SetCallback([this] { this->RefPtrCallback(); }); -#ifdef OHOS_PLATFORM refs_->SetCanPromote([this] { return this->CanPromote(); }); -#endif } RefBase::RefBase(const RefBase &) @@ -485,18 +479,14 @@ RefBase::RefBase(const RefBase &) if (refs_ != nullptr) { refs_->IncRefCount(); refs_->SetCallback([this] { this->RefPtrCallback(); }); -#ifdef OHOS_PLATFORM refs_->SetCanPromote([this] { return this->CanPromote(); }); -#endif } } -#ifdef OHOS_PLATFORM bool RefBase::CanPromote() { return true; } -#endif void RefBase::RefPtrCallback() { @@ -520,9 +510,7 @@ RefBase &RefBase::operator=(const RefBase &) if (refs_ != nullptr) { refs_->IncRefCount(); refs_->SetCallback([this] { this->RefPtrCallback(); }); -#ifdef OHOS_PLATFORM refs_->SetCanPromote([this] { return this->CanPromote(); }); -#endif } return *this; diff --git a/base/test/unittest/common/utils_refbase_test.cpp b/base/test/unittest/common/utils_refbase_test.cpp index 4041e2e..0a8abe0 100644 --- a/base/test/unittest/common/utils_refbase_test.cpp +++ b/base/test/unittest/common/utils_refbase_test.cpp @@ -1337,11 +1337,9 @@ HWTEST_F(UtilsRefbaseTest, testRefbaseWithDomainIdDebug004, TestSize.Level1) HWTEST_F(UtilsRefbaseTest, testRefCounter001, TestSize.Level1) { RefCounter *refCounterTest = new RefCounter(); -#ifdef OHOS_PLATFORM refCounterTest->RemoveCanPromote(); bool result = refCounterTest->IsCanPromoteValid(); EXPECT_EQ(result, false); -#endif delete refCounterTest; } } // namespace -- Gitee