diff --git a/base/BUILD.gn b/base/BUILD.gn index 4778c4402821cc6e22f75b3606266537b8ec907e..d53a863b954887914c8b5d099ad34dca4a3ca11f 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -32,6 +32,9 @@ config("utils_config") { if (is_emulator == true) { defines += [ "EMULATOR_PLATFORM" ] } + if (current_os == "ohos") { + defines += [ "OHOS_PLATFORM" ] + } } config("utils_coverage_config") { diff --git a/base/include/refbase.h b/base/include/refbase.h index af3f6d6c8d83ea623646d59667108dee9269e832..089fc4b5c98ce889e0cb35c7dcafcee2bc1b2bcb 100644 --- a/base/include/refbase.h +++ b/base/include/refbase.h @@ -240,7 +240,7 @@ public: */ void ExtendObjectLifetime(); -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM using CanPromote = std::function; void SetCanPromote(const CanPromote& canPromote); @@ -267,7 +267,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 -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM CanPromote canPromote_ = nullptr; #endif #ifdef DEBUG_REFBASE @@ -595,7 +595,7 @@ public: */ void EnableTracker(); -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM virtual bool CanPromote(); #endif diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index cb7426f1ceb7e278c83f066afd98041341d9e7f2..a39676c1989d7da4622cc56e95164713643584ab 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -211,7 +211,7 @@ bool RefCounter::IsRefPtrValid() return callback_ != nullptr; } -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM void RefCounter::SetCanPromote(const CanPromote &canPromote) { canPromote_ = canPromote; @@ -374,7 +374,7 @@ bool RefCounter::AttemptIncStrongRef(const void *objectId, int &outCount) } if (IsLifeTimeExtended()) { -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM if (!IsCanPromoteValid() || !canPromote_()) { return false; } @@ -418,7 +418,7 @@ RefBase::RefBase() : refs_(new RefCounter()) { refs_->IncRefCount(); refs_->SetCallback([this] { this->RefPtrCallback(); }); -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM refs_->SetCanPromote([this] { return this->CanPromote(); }); #endif } @@ -429,13 +429,13 @@ RefBase::RefBase(const RefBase &) if (refs_ != nullptr) { refs_->IncRefCount(); refs_->SetCallback([this] { this->RefPtrCallback(); }); -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM refs_->SetCanPromote([this] { return this->CanPromote(); }); #endif } } -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM bool RefBase::CanPromote() { return true; @@ -464,7 +464,7 @@ RefBase &RefBase::operator=(const RefBase &) if (refs_ != nullptr) { refs_->IncRefCount(); refs_->SetCallback([this] { this->RefPtrCallback(); }); -#ifndef EMULATOR_PLATFORM +#ifdef OHOS_PLATFORM refs_->SetCanPromote([this] { return this->CanPromote(); }); #endif }