summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.h
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-12-29 10:55:30 -0200
committerGravatar Yuri Kunde Schlesner2015-01-09 19:43:52 -0200
commit8ad41775ccae67e54e9f03cbe054d7562b1c66ce (patch)
tree79d176bd9805cae0a2cfdd12e4c91c108bec0c8d /src/core/hle/kernel/kernel.h
parentKernel: Don't re-assign object's handle when duplicating one (diff)
downloadyuzu-8ad41775ccae67e54e9f03cbe054d7562b1c66ce.tar.gz
yuzu-8ad41775ccae67e54e9f03cbe054d7562b1c66ce.tar.xz
yuzu-8ad41775ccae67e54e9f03cbe054d7562b1c66ce.zip
Kernel: Start using boost::intrusive_ptr for lifetime management
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
-rw-r--r--src/core/hle/kernel/kernel.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index a35055724..5e5217b78 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -4,6 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <boost/intrusive_ptr.hpp>
8
7#include <array> 9#include <array>
8#include <string> 10#include <string>
9#include "common/common.h" 11#include "common/common.h"
@@ -76,7 +78,7 @@ private:
76 unsigned int ref_count = 0; 78 unsigned int ref_count = 0;
77}; 79};
78 80
79// Special functions that will later be used by boost::instrusive_ptr to do automatic ref-counting 81// Special functions used by boost::instrusive_ptr to do automatic ref-counting
80inline void intrusive_ptr_add_ref(Object* object) { 82inline void intrusive_ptr_add_ref(Object* object) {
81 ++object->ref_count; 83 ++object->ref_count;
82} 84}
@@ -87,6 +89,9 @@ inline void intrusive_ptr_release(Object* object) {
87 } 89 }
88} 90}
89 91
92template <typename T>
93using SharedPtr = boost::intrusive_ptr<T>;
94
90/** 95/**
91 * This class allows the creation of Handles, which are references to objects that can be tested 96 * This class allows the creation of Handles, which are references to objects that can be tested
92 * for validity and looked up. Here they are used to pass references to kernel objects to/from the 97 * for validity and looked up. Here they are used to pass references to kernel objects to/from the
@@ -119,7 +124,7 @@ public:
119 * @return The created Handle or one of the following errors: 124 * @return The created Handle or one of the following errors:
120 * - `ERR_OUT_OF_HANDLES`: the maximum number of handles has been exceeded. 125 * - `ERR_OUT_OF_HANDLES`: the maximum number of handles has been exceeded.
121 */ 126 */
122 ResultVal<Handle> Create(Object* obj); 127 ResultVal<Handle> Create(SharedPtr<Object> obj);
123 128
124 /** 129 /**
125 * Returns a new handle that points to the same object as the passed in handle. 130 * Returns a new handle that points to the same object as the passed in handle.
@@ -143,7 +148,7 @@ public:
143 * Looks up a handle. 148 * Looks up a handle.
144 * @returns Pointer to the looked-up object, or `nullptr` if the handle is not valid. 149 * @returns Pointer to the looked-up object, or `nullptr` if the handle is not valid.
145 */ 150 */
146 Object* GetGeneric(Handle handle) const; 151 SharedPtr<Object> GetGeneric(Handle handle) const;
147 152
148 /** 153 /**
149 * Looks up a handle while verifying its type. 154 * Looks up a handle while verifying its type.
@@ -151,10 +156,10 @@ public:
151 * type differs from the handle type `T::HANDLE_TYPE`. 156 * type differs from the handle type `T::HANDLE_TYPE`.
152 */ 157 */
153 template <class T> 158 template <class T>
154 T* Get(Handle handle) const { 159 SharedPtr<T> Get(Handle handle) const {
155 Object* object = GetGeneric(handle); 160 SharedPtr<Object> object = GetGeneric(handle);
156 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { 161 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
157 return static_cast<T*>(object); 162 return boost::static_pointer_cast<T>(std::move(object));
158 } 163 }
159 return nullptr; 164 return nullptr;
160 } 165 }
@@ -173,7 +178,7 @@ private:
173 static u16 GetGeneration(Handle handle) { return handle & 0x7FFF; } 178 static u16 GetGeneration(Handle handle) { return handle & 0x7FFF; }
174 179
175 /// Stores the Object referenced by the handle or null if the slot is empty. 180 /// Stores the Object referenced by the handle or null if the slot is empty.
176 std::array<Object*, MAX_COUNT> objects; 181 std::array<SharedPtr<Object>, MAX_COUNT> objects;
177 182
178 /** 183 /**
179 * The value of `next_generation` when the handle was created, used to check for validity. For 184 * The value of `next_generation` when the handle was created, used to check for validity. For
@@ -192,7 +197,7 @@ private:
192}; 197};
193 198
194extern HandleTable g_handle_table; 199extern HandleTable g_handle_table;
195extern Thread* g_main_thread; 200extern SharedPtr<Thread> g_main_thread;
196 201
197/// The ID code of the currently running game 202/// The ID code of the currently running game
198/// TODO(Subv): This variable should not be here, 203/// TODO(Subv): This variable should not be here,