diff options
| author | 2017-05-29 14:42:27 -0700 | |
|---|---|---|
| committer | 2017-05-29 14:42:27 -0700 | |
| commit | b17754f998f225f3de9df59c917c7b88f81aaf22 (patch) | |
| tree | c2f7f43f0b95497b60fcd2aba37215665f7c0e4c /src/core | |
| parent | Merge pull request #2729 from yuriks/quaternion-fix (diff) | |
| download | yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.gz yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.xz yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.zip | |
Kernel: Extract dynamic Object pointer cast into its own function
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 94f2025a0..d8929259e 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -121,6 +121,18 @@ inline void intrusive_ptr_release(Object* object) { | |||
| 121 | template <typename T> | 121 | template <typename T> |
| 122 | using SharedPtr = boost::intrusive_ptr<T>; | 122 | using SharedPtr = boost::intrusive_ptr<T>; |
| 123 | 123 | ||
| 124 | /** | ||
| 125 | * Attempts to downcast the given Object pointer to a pointer to T. | ||
| 126 | * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. | ||
| 127 | */ | ||
| 128 | template <typename T> | ||
| 129 | inline SharedPtr<T> DynamicObjectCast(SharedPtr<Object> object) { | ||
| 130 | if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { | ||
| 131 | return boost::static_pointer_cast<T>(std::move(object)); | ||
| 132 | } | ||
| 133 | return nullptr; | ||
| 134 | } | ||
| 135 | |||
| 124 | /// Class that represents a Kernel object that a thread can be waiting on | 136 | /// Class that represents a Kernel object that a thread can be waiting on |
| 125 | class WaitObject : public Object { | 137 | class WaitObject : public Object { |
| 126 | public: | 138 | public: |
| @@ -163,6 +175,15 @@ private: | |||
| 163 | std::vector<SharedPtr<Thread>> waiting_threads; | 175 | std::vector<SharedPtr<Thread>> waiting_threads; |
| 164 | }; | 176 | }; |
| 165 | 177 | ||
| 178 | // Specialization of DynamicObjectCast for WaitObjects | ||
| 179 | template <> | ||
| 180 | inline SharedPtr<WaitObject> DynamicObjectCast<WaitObject>(SharedPtr<Object> object) { | ||
| 181 | if (object != nullptr && object->IsWaitable()) { | ||
| 182 | return boost::static_pointer_cast<WaitObject>(std::move(object)); | ||
| 183 | } | ||
| 184 | return nullptr; | ||
| 185 | } | ||
| 186 | |||
| 166 | /** | 187 | /** |
| 167 | * This class allows the creation of Handles, which are references to objects that can be tested | 188 | * This class allows the creation of Handles, which are references to objects that can be tested |
| 168 | * for validity and looked up. Here they are used to pass references to kernel objects to/from the | 189 | * for validity and looked up. Here they are used to pass references to kernel objects to/from the |
| @@ -224,15 +245,11 @@ public: | |||
| 224 | /** | 245 | /** |
| 225 | * Looks up a handle while verifying its type. | 246 | * Looks up a handle while verifying its type. |
| 226 | * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid or its | 247 | * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid or its |
| 227 | * type differs from the handle type `T::HANDLE_TYPE`. | 248 | * type differs from the requested one. |
| 228 | */ | 249 | */ |
| 229 | template <class T> | 250 | template <class T> |
| 230 | SharedPtr<T> Get(Handle handle) const { | 251 | SharedPtr<T> Get(Handle handle) const { |
| 231 | SharedPtr<Object> object = GetGeneric(handle); | 252 | return DynamicObjectCast<T>(GetGeneric(handle)); |
| 232 | if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { | ||
| 233 | return boost::static_pointer_cast<T>(std::move(object)); | ||
| 234 | } | ||
| 235 | return nullptr; | ||
| 236 | } | 253 | } |
| 237 | 254 | ||
| 238 | /** | 255 | /** |
| @@ -241,11 +258,7 @@ public: | |||
| 241 | * not a waitable object. | 258 | * not a waitable object. |
| 242 | */ | 259 | */ |
| 243 | SharedPtr<WaitObject> GetWaitObject(Handle handle) const { | 260 | SharedPtr<WaitObject> GetWaitObject(Handle handle) const { |
| 244 | SharedPtr<Object> object = GetGeneric(handle); | 261 | return DynamicObjectCast<WaitObject>(GetGeneric(handle)); |
| 245 | if (object != nullptr && object->IsWaitable()) { | ||
| 246 | return boost::static_pointer_cast<WaitObject>(std::move(object)); | ||
| 247 | } | ||
| 248 | return nullptr; | ||
| 249 | } | 262 | } |
| 250 | 263 | ||
| 251 | /// Closes all handles held in this table. | 264 | /// Closes all handles held in this table. |