From 0147bc2c72e64b4673f37e163ecf6a45a6f9323a Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 20 Jan 2020 19:08:31 +0300 Subject: [PATCH] Fixup shared_cptr, atomic_cptr --- rpcs3/util/shared_cptr.hpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/rpcs3/util/shared_cptr.hpp b/rpcs3/util/shared_cptr.hpp index a299259c4b..6f75abc1ba 100644 --- a/rpcs3/util/shared_cptr.hpp +++ b/rpcs3/util/shared_cptr.hpp @@ -42,6 +42,9 @@ namespace stx // Combined borrowed refcounter and object pointer mutable ptr_type m_val; + template + friend class atomic_cptr; + constexpr atomic_base() noexcept : m_val(0) { @@ -130,7 +133,7 @@ namespace stx long long fetch_add(long long value) { #ifdef _MSC_VER - return _InterlockedExchangeAdd64(&m_ref_count, &value); + return _InterlockedExchangeAdd64(&m_ref_count, value); #else return __atomic_fetch_add(&m_ref_count, value, __ATOMIC_SEQ_CST); #endif @@ -226,6 +229,9 @@ namespace stx { using cb = atomic_base; + protected: + using atomic_base::m_val; + public: constexpr shared_cptr() noexcept : atomic_base() @@ -338,7 +344,7 @@ namespace stx std::conditional_t get() const noexcept { - return &this->ptr_get()->m_value; + return &this->ptr_get()->m_data; } std::conditional_t operator*() const noexcept @@ -418,13 +424,13 @@ namespace stx base load() const noexcept { base result; - result->m_val = this->ref_load(); + static_cast(result).m_val = this->ref_load(); if (result) { // TODO: obtain max-1 and try to return as much as possible this->template ptr_get()->fetch_add(1); - this->ref_fix(result->m_val); + this->ref_fix(static_cast(result).m_val); } return result; @@ -437,7 +443,7 @@ namespace stx base exchange(base value) noexcept { - value->m_val = this->val_exchange(value->m_val); + static_cast(value).m_val = this->val_exchange(static_cast(value).m_val); return value; } @@ -478,6 +484,8 @@ namespace stx // } // void atomic_op(); + + using base::make; }; template