summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
authorYuri Kunde Schlesner <yuriks@yuriks.net>2017-05-29 23:42:27 +0200
committerYuri Kunde Schlesner <yuriks@yuriks.net>2017-05-29 23:42:27 +0200
commitb17754f998f225f3de9df59c917c7b88f81aaf22 (patch)
treec2f7f43f0b95497b60fcd2aba37215665f7c0e4c /src/core/hle
parentMerge pull request #2729 from yuriks/quaternion-fix (diff)
downloadyuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar
yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.gz
yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.bz2
yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.lz
yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.xz
yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.tar.zst
yuzu-b17754f998f225f3de9df59c917c7b88f81aaf22.zip
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/kernel/kernel.h35
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) {
template <typename T>
using SharedPtr = boost::intrusive_ptr<T>;
+/**
+ * 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) {
+ if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
+ return boost::static_pointer_cast<T>(std::move(object));
+ }
+ return nullptr;
+}
+
/// Class that represents a Kernel object that a thread can be waiting on
class WaitObject : public Object {
public:
@@ -163,6 +175,15 @@ private:
std::vector<SharedPtr<Thread>> waiting_threads;
};
+// Specialization of DynamicObjectCast for WaitObjects
+template <>
+inline SharedPtr<WaitObject> DynamicObjectCast<WaitObject>(SharedPtr<Object> object) {
+ if (object != nullptr && object->IsWaitable()) {
+ return boost::static_pointer_cast<WaitObject>(std::move(object));
+ }
+ return nullptr;
+}
+
/**
* 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
@@ -224,15 +245,11 @@ public:
/**
* Looks up a handle while verifying its type.
* @return Pointer to the looked-up object, or `nullptr` if the handle is not valid or its
- * type differs from the handle type `T::HANDLE_TYPE`.
+ * type differs from the requested one.
*/
template <class T>
SharedPtr<T> Get(Handle handle) const {
- SharedPtr<Object> object = GetGeneric(handle);
- if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
- return boost::static_pointer_cast<T>(std::move(object));
- }
- return nullptr;
+ return DynamicObjectCast<T>(GetGeneric(handle));
}
/**
@@ -241,11 +258,7 @@ public:
* not a waitable object.
*/
SharedPtr<WaitObject> GetWaitObject(Handle handle) const {
- SharedPtr<Object> object = GetGeneric(handle);
- if (object != nullptr && object->IsWaitable()) {
- return boost::static_pointer_cast<WaitObject>(std::move(object));
- }
- return nullptr;
+ return DynamicObjectCast<WaitObject>(GetGeneric(handle));
}
/// Closes all handles held in this table.