diff --git a/base/include/refbase.h b/base/include/refbase.h index 8122d81806de6805dd1dd9b5003e2c39630381e6..01fef21159a0125ee4fe300addbe3bcc3f714006 100644 --- a/base/include/refbase.h +++ b/base/include/refbase.h @@ -212,6 +212,12 @@ public: virtual void OnLastWeakRef(const void *objectId); virtual bool OnAttemptPromoted(const void *objectId); + /** + * @brief Get the pointer to corresponding counter object. + * + * @return Pointer to the counter object. + */ + RefCounter *GetRefCounter() const; private: RefCounter *refs_ = nullptr; diff --git a/base/src/refbase.cpp b/base/src/refbase.cpp index fb46127f919b6024c883061de5f70fdac833f2b7..54f25572f1ac12a5b2979b3a68406771ee3d9184 100644 --- a/base/src/refbase.cpp +++ b/base/src/refbase.cpp @@ -361,7 +361,6 @@ bool RefCounter::AttemptIncStrong(const void *objectId) if (atomicStrong_.compare_exchange_weak(curCount, curCount + 1, std::memory_order_relaxed)) { break; } - curCount = atomicStrong_.load(std::memory_order_relaxed); } if (curCount <= 0) { DecWeakRefCount(objectId); @@ -510,6 +509,10 @@ void RefBase::IncWeakRef(const void *objectId) refs_->IncWeakRefCount(objectId); } } +RefCounter *RefBase::GetRefCounter() const +{ + return refs_; +} void RefBase::DecWeakRef(const void *objectId) {