From 8ad41775ccae67e54e9f03cbe054d7562b1c66ce Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 29 Dec 2014 10:55:30 -0200 Subject: Kernel: Start using boost::intrusive_ptr for lifetime management --- src/core/hle/kernel/kernel.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/core/hle/kernel/kernel.h') diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index a3505572..5e5217b7 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -4,6 +4,8 @@ #pragma once +#include + #include #include #include "common/common.h" @@ -76,7 +78,7 @@ private: unsigned int ref_count = 0; }; -// Special functions that will later be used by boost::instrusive_ptr to do automatic ref-counting +// Special functions used by boost::instrusive_ptr to do automatic ref-counting inline void intrusive_ptr_add_ref(Object* object) { ++object->ref_count; } @@ -87,6 +89,9 @@ inline void intrusive_ptr_release(Object* object) { } } +template +using SharedPtr = boost::intrusive_ptr; + /** * This class allows the creation of Handles, which are references to objects that can be tested * for validity and looked up. Here they are used to pass references to kernel objects to/from the @@ -119,7 +124,7 @@ public: * @return The created Handle or one of the following errors: * - `ERR_OUT_OF_HANDLES`: the maximum number of handles has been exceeded. */ - ResultVal Create(Object* obj); + ResultVal Create(SharedPtr obj); /** * Returns a new handle that points to the same object as the passed in handle. @@ -143,7 +148,7 @@ public: * Looks up a handle. * @returns Pointer to the looked-up object, or `nullptr` if the handle is not valid. */ - Object* GetGeneric(Handle handle) const; + SharedPtr GetGeneric(Handle handle) const; /** * Looks up a handle while verifying its type. @@ -151,10 +156,10 @@ public: * type differs from the handle type `T::HANDLE_TYPE`. */ template - T* Get(Handle handle) const { - Object* object = GetGeneric(handle); + SharedPtr Get(Handle handle) const { + SharedPtr object = GetGeneric(handle); if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { - return static_cast(object); + return boost::static_pointer_cast(std::move(object)); } return nullptr; } @@ -173,7 +178,7 @@ private: static u16 GetGeneration(Handle handle) { return handle & 0x7FFF; } /// Stores the Object referenced by the handle or null if the slot is empty. - std::array objects; + std::array, MAX_COUNT> objects; /** * The value of `next_generation` when the handle was created, used to check for validity. For @@ -192,7 +197,7 @@ private: }; extern HandleTable g_handle_table; -extern Thread* g_main_thread; +extern SharedPtr g_main_thread; /// The ID code of the currently running game /// TODO(Subv): This variable should not be here, -- cgit v1.2.3