diff options
author | bunnei <bunneidev@gmail.com> | 2019-11-25 02:15:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-25 02:15:51 +0100 |
commit | 9046d4a5485452802b756869b7d27056ba9ea9d7 (patch) | |
tree | 2d704d912e9054fb232b73ad69f1bc3966ed97a5 /src/core/hle/kernel/object.h | |
parent | Merge pull request #3098 from ReinUsesLisp/shader-invalidations (diff) | |
download | yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.gz yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.bz2 yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.lz yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.xz yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.zst yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.zip |
Diffstat (limited to 'src/core/hle/kernel/object.h')
-rw-r--r-- | src/core/hle/kernel/object.h | 30 |
1 files changed, 9 insertions, 21 deletions
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 <atomic> +#include <memory> #include <string> -#include <boost/smart_ptr/intrusive_ptr.hpp> - #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<Object> { 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<u32> ref_count{0}; std::atomic<u32> 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 <typename T> -using SharedPtr = boost::intrusive_ptr<T>; +std::shared_ptr<T> SharedFrom(T* raw) { + if (raw == nullptr) + return nullptr; + return std::static_pointer_cast<T>(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 <typename T> -inline SharedPtr<T> DynamicObjectCast(SharedPtr<Object> object) { +inline std::shared_ptr<T> DynamicObjectCast(std::shared_ptr<Object> object) { if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { - return boost::static_pointer_cast<T>(object); + return std::static_pointer_cast<T>(object); } return nullptr; } |