diff --git a/base/include/refbase.h b/base/include/refbase.h index 68fb082d3a62f76feb3e3bd3bc0b1ae1687291b7..cee9a694d9d6a688168c787eb4f54fc59e5d47dc 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 37eba341d8b3e46c90c0da67a0b56a0bd9e2d8b6..60e26d30d918ec3a225fac3ab0757d9e0953273b 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 4041e2e2aa431d619c155403ddadfc6413cf981f..0a8abe02bbc0f3d27e79a6bbe83b94ac0da537f4 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