diff --git a/starboard/common/ref_counted.cc b/starboard/common/ref_counted.cc index 4d8992d7d2f75..4b858357899b5 100644 --- a/starboard/common/ref_counted.cc +++ b/starboard/common/ref_counted.cc @@ -54,8 +54,7 @@ bool RefCountedBase::Release() const { } bool RefCountedThreadSafeBase::HasOneRef() const { - return (SbAtomicAcquire_Load( - &const_cast(this)->ref_count_) == 1); + return ref_count_.load(std::memory_order_acquire) == 1; } RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) { @@ -75,15 +74,15 @@ void RefCountedThreadSafeBase::AddRef() const { #ifndef NDEBUG SB_DCHECK(!in_dtor_); #endif - SbAtomicNoBarrier_Increment(&ref_count_, 1); + ref_count_.fetch_add(1, std::memory_order_relaxed); } bool RefCountedThreadSafeBase::Release() const { #ifndef NDEBUG SB_DCHECK(!in_dtor_); - SB_DCHECK(!(SbAtomicAcquire_Load(&ref_count_) == 0)); + SB_DCHECK(!(ref_count_.load(std::memory_order_relaxed) == 0)); #endif - if (SbAtomicBarrier_Increment(&ref_count_, -1) == 0) { + if (ref_count_.fetch_sub(1, std::memory_order_acq_rel) == 1) { #ifndef NDEBUG in_dtor_ = true; #endif diff --git a/starboard/common/ref_counted.h b/starboard/common/ref_counted.h index 4c3c8c3f5847f..d9f5db76ae5c4 100644 --- a/starboard/common/ref_counted.h +++ b/starboard/common/ref_counted.h @@ -6,11 +6,10 @@ #define STARBOARD_COMMON_REF_COUNTED_H_ #include +#include #include -#include "starboard/atomic.h" #include "starboard/common/log.h" -#include "starboard/common/thread_collision_warner.h" namespace starboard { namespace subtle { @@ -33,8 +32,6 @@ class RefCountedBase { #ifndef NDEBUG mutable bool in_dtor_; #endif - - DFAKE_MUTEX(add_release_); }; class RefCountedThreadSafeBase { @@ -51,7 +48,7 @@ class RefCountedThreadSafeBase { bool Release() const; private: - mutable SbAtomic32 ref_count_; + mutable std::atomic ref_count_; #ifndef NDEBUG mutable bool in_dtor_; #endif