summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-05-01 21:36:21 +0200
committerbunnei <bunneidev@gmail.com>2021-05-06 01:40:53 +0200
commit25538db150a90f01356c238e65548ccf3e797cd8 (patch)
treee869a008fa8851dea774aef7d5e5fb7d51ac19b0 /src/core/hle/kernel
parentfixup! hle: kernel: Add initial impl. of KAutoObject. (diff)
downloadyuzu-25538db150a90f01356c238e65548ccf3e797cd8.tar
yuzu-25538db150a90f01356c238e65548ccf3e797cd8.tar.gz
yuzu-25538db150a90f01356c238e65548ccf3e797cd8.tar.bz2
yuzu-25538db150a90f01356c238e65548ccf3e797cd8.tar.lz
yuzu-25538db150a90f01356c238e65548ccf3e797cd8.tar.xz
yuzu-25538db150a90f01356c238e65548ccf3e797cd8.tar.zst
yuzu-25538db150a90f01356c238e65548ccf3e797cd8.zip
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/k_auto_object.h92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/core/hle/kernel/k_auto_object.h b/src/core/hle/kernel/k_auto_object.h
index 452325f73..765e46670 100644
--- a/src/core/hle/kernel/k_auto_object.h
+++ b/src/core/hle/kernel/k_auto_object.h
@@ -5,6 +5,7 @@
#pragma once
#include <atomic>
+#include <string>
#include "common/assert.h"
#include "common/common_funcs.h"
@@ -45,19 +46,15 @@ public:
return GetStaticTypeName(); \
} \
\
-private:
+private: \
+ constexpr bool operator!=(const TypeObj& rhs)
class KAutoObject {
protected:
class TypeObj {
- private:
- const char* m_name;
- ClassTokenType m_class_token;
-
public:
constexpr explicit TypeObj(const char* n, ClassTokenType tok)
- : m_name(n), m_class_token(tok) { // ...
- }
+ : m_name(n), m_class_token(tok) {}
constexpr const char* GetName() const {
return m_name;
@@ -66,35 +63,31 @@ protected:
return m_class_token;
}
- constexpr bool operator==(const TypeObj& rhs) {
+ constexpr bool operator==(const TypeObj& rhs) const {
return this->GetClassToken() == rhs.GetClassToken();
}
- constexpr bool operator!=(const TypeObj& rhs) {
+ constexpr bool operator!=(const TypeObj& rhs) const {
return this->GetClassToken() != rhs.GetClassToken();
}
- constexpr bool IsDerivedFrom(const TypeObj& rhs) {
+ constexpr bool IsDerivedFrom(const TypeObj& rhs) const {
return (this->GetClassToken() | rhs.GetClassToken()) == this->GetClassToken();
}
+
+ private:
+ const char* m_name;
+ ClassTokenType m_class_token;
};
private:
KERNEL_AUTOOBJECT_TRAITS(KAutoObject, KAutoObject);
-private:
- std::atomic<u32> m_ref_count{};
-
-protected:
- KernelCore& kernel;
- std::string name;
-
-public:
- static KAutoObject* Create(KAutoObject* ptr);
-
public:
explicit KAutoObject(KernelCore& kernel_) : kernel(kernel_) {}
- virtual ~KAutoObject() {}
+ virtual ~KAutoObject() = default;
+
+ static KAutoObject* Create(KAutoObject* ptr);
// Destroy is responsible for destroying the auto object's resources when ref_count hits zero.
virtual void Destroy() {
@@ -122,8 +115,8 @@ public:
template <typename Derived>
Derived DynamicCast() {
- static_assert(std::is_pointer<Derived>::value);
- using DerivedType = typename std::remove_pointer<Derived>::type;
+ static_assert(std::is_pointer_v<Derived>);
+ using DerivedType = std::remove_pointer_t<Derived>;
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
return static_cast<Derived>(this);
@@ -134,8 +127,8 @@ public:
template <typename Derived>
const Derived DynamicCast() const {
- static_assert(std::is_pointer<Derived>::value);
- using DerivedType = typename std::remove_pointer<Derived>::type;
+ static_assert(std::is_pointer_v<Derived>);
+ using DerivedType = std::remove_pointer_t<Derived>;
if (this->IsDerivedFrom(DerivedType::GetStaticTypeObj())) {
return static_cast<Derived>(this);
@@ -171,20 +164,18 @@ public:
this->Destroy();
}
}
-};
-
-class KAutoObjectWithListContainer;
-class KAutoObjectWithList : public KAutoObject {
-private:
- friend class KAutoObjectWithListContainer;
+protected:
+ KernelCore& kernel;
+ std::string name;
private:
- Common::IntrusiveRedBlackTreeNode list_node;
+ std::atomic<u32> m_ref_count{};
+};
-protected:
- KernelCore& kernel;
+class KAutoObjectWithListContainer;
+class KAutoObjectWithList : public KAutoObject {
public:
explicit KAutoObjectWithList(KernelCore& kernel_) : KAutoObject(kernel_), kernel(kernel_) {}
@@ -209,23 +200,20 @@ public:
virtual const std::string& GetName() const {
return name;
}
-};
-
-template <typename T>
-class KScopedAutoObject {
- YUZU_NON_COPYABLE(KScopedAutoObject);
private:
- template <typename U>
- friend class KScopedAutoObject;
+ friend class KAutoObjectWithListContainer;
private:
- T* m_obj{};
+ Common::IntrusiveRedBlackTreeNode list_node;
-private:
- constexpr void Swap(KScopedAutoObject& rhs) {
- std::swap(m_obj, rhs.m_obj);
- }
+protected:
+ KernelCore& kernel;
+};
+
+template <typename T>
+class KScopedAutoObject {
+ YUZU_NON_COPYABLE(KScopedAutoObject);
public:
constexpr KScopedAutoObject() = default;
@@ -301,6 +289,18 @@ public:
constexpr bool IsNotNull() const {
return m_obj != nullptr;
}
+
+private:
+ template <typename U>
+ friend class KScopedAutoObject;
+
+private:
+ T* m_obj{};
+
+private:
+ constexpr void Swap(KScopedAutoObject& rhs) noexcept {
+ std::swap(m_obj, rhs.m_obj);
+ }
};
} // namespace Kernel