From 9046d4a5485452802b756869b7d27056ba9ea9d7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 24 Nov 2019 20:15:51 -0500 Subject: kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. (#3154) * kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. - See https://github.com/citra-emu/citra/pull/4710 for details. --- src/core/hle/kernel/object.h | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'src/core/hle/kernel/object.h') diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h index a6faeb83b..bbbb4e7cc 100644 --- a/src/core/hle/kernel/object.h +++ b/src/core/hle/kernel/object.h @@ -5,10 +5,9 @@ #pragma once #include +#include #include -#include - #include "common/common_types.h" namespace Kernel { @@ -32,7 +31,7 @@ enum class HandleType : u32 { ServerSession, }; -class Object : NonCopyable { +class Object : NonCopyable, public std::enable_shared_from_this { public: explicit Object(KernelCore& kernel); virtual ~Object(); @@ -61,35 +60,24 @@ protected: KernelCore& kernel; private: - friend void intrusive_ptr_add_ref(Object*); - friend void intrusive_ptr_release(Object*); - - std::atomic ref_count{0}; std::atomic object_id{0}; }; -// Special functions used by boost::instrusive_ptr to do automatic ref-counting -inline void intrusive_ptr_add_ref(Object* object) { - object->ref_count.fetch_add(1, std::memory_order_relaxed); -} - -inline void intrusive_ptr_release(Object* object) { - if (object->ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1) { - delete object; - } -} - template -using SharedPtr = boost::intrusive_ptr; +std::shared_ptr SharedFrom(T* raw) { + if (raw == nullptr) + return nullptr; + return std::static_pointer_cast(raw->shared_from_this()); +} /** * Attempts to downcast the given Object pointer to a pointer to T. * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. */ template -inline SharedPtr DynamicObjectCast(SharedPtr object) { +inline std::shared_ptr DynamicObjectCast(std::shared_ptr object) { if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { - return boost::static_pointer_cast(object); + return std::static_pointer_cast(object); } return nullptr; } -- cgit v1.2.3