From 77aa9e58f2c45f507248923b948921293332cec7 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 6 Dec 2020 11:13:34 +0300 Subject: [PATCH] shared_ptr.hpp: add trivial conversion for shared/single types These conversions don't exist in std::shared_ptr-alike types. But I don't want to bother with == operators until we have proper C++20. Removed trivial conversion for atomic_ptr because it's heavyweight. --- Utilities/Thread.cpp | 8 +++++++- rpcs3/Emu/Cell/PPUThread.cpp | 8 +++++++- rpcs3/Emu/Cell/SPUThread.cpp | 8 +++++++- rpcs3/util/shared_ptr.hpp | 15 ++++++++++----- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 166f8aeb00..432dd31cbe 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -2250,7 +2250,13 @@ std::string thread_ctrl::get_name_cached() if (!_this->m_tname.is_equal(name_cache)) [[unlikely]] { - name_cache = _this->m_tname.load(); + _this->m_tname.peek_op([&](const shared_ptr& ptr) + { + if (ptr != name_cache) + { + name_cache = ptr; + } + }); } return *name_cache; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 1870afcd88..cec21f4fc8 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1049,7 +1049,13 @@ void ppu_thread::fast_call(u32 addr, u32 rtoc) if (!_this->ppu_tname.is_equal(name_cache)) [[unlikely]] { - name_cache = _this->ppu_tname.load(); + _this->ppu_tname.peek_op([&](const shared_ptr& ptr) + { + if (ptr != name_cache) + { + name_cache = ptr; + } + }); } const auto cia = _this->cia; diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 8aa4da0bfd..37da1d2297 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1615,7 +1615,13 @@ void spu_thread::cpu_task() if (!cpu->spu_tname.is_equal(name_cache)) [[unlikely]] { - name_cache = cpu->spu_tname.load(); + cpu->spu_tname.peek_op([&](const shared_ptr& ptr) + { + if (ptr != name_cache) + { + name_cache = ptr; + } + }); } const auto type = cpu->get_type(); diff --git a/rpcs3/util/shared_ptr.hpp b/rpcs3/util/shared_ptr.hpp index c3a9bc06d1..2ec55d70be 100644 --- a/rpcs3/util/shared_ptr.hpp +++ b/rpcs3/util/shared_ptr.hpp @@ -205,6 +205,11 @@ namespace stx } } + operator element_type*() const noexcept + { + return m_ptr; + } + explicit constexpr operator bool() const noexcept { return m_ptr != nullptr; @@ -521,6 +526,11 @@ namespace stx } } + operator element_type*() const noexcept + { + return m_ptr; + } + explicit constexpr operator bool() const noexcept { return m_ptr != nullptr; @@ -731,11 +741,6 @@ namespace stx return r; } - operator shared_type() const noexcept - { - return load(); - } - // Atomically inspect pointer with the possibility to reference it if necessary template > RT peek_op(F op) const noexcept