diff options
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 402ae900f..2bc45d7db 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -4,120 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstddef> | ||
| 8 | #include <string> | ||
| 9 | #include <utility> | ||
| 10 | #include <boost/smart_ptr/intrusive_ptr.hpp> | ||
| 11 | #include "common/assert.h" | ||
| 12 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 13 | 8 | ||
| 14 | namespace Kernel { | 9 | namespace Kernel { |
| 15 | 10 | ||
| 16 | using Handle = u32; | ||
| 17 | |||
| 18 | enum class HandleType : u32 { | ||
| 19 | Unknown, | ||
| 20 | Event, | ||
| 21 | SharedMemory, | ||
| 22 | Thread, | ||
| 23 | Process, | ||
| 24 | AddressArbiter, | ||
| 25 | Timer, | ||
| 26 | ResourceLimit, | ||
| 27 | CodeSet, | ||
| 28 | ClientPort, | ||
| 29 | ServerPort, | ||
| 30 | ClientSession, | ||
| 31 | ServerSession, | ||
| 32 | }; | ||
| 33 | |||
| 34 | enum class ResetType { | ||
| 35 | OneShot, | ||
| 36 | Sticky, | ||
| 37 | Pulse, | ||
| 38 | }; | ||
| 39 | |||
| 40 | class Object : NonCopyable { | ||
| 41 | public: | ||
| 42 | virtual ~Object() {} | ||
| 43 | |||
| 44 | /// Returns a unique identifier for the object. For debugging purposes only. | ||
| 45 | unsigned int GetObjectId() const { | ||
| 46 | return object_id; | ||
| 47 | } | ||
| 48 | |||
| 49 | virtual std::string GetTypeName() const { | ||
| 50 | return "[BAD KERNEL OBJECT TYPE]"; | ||
| 51 | } | ||
| 52 | virtual std::string GetName() const { | ||
| 53 | return "[UNKNOWN KERNEL OBJECT]"; | ||
| 54 | } | ||
| 55 | virtual Kernel::HandleType GetHandleType() const = 0; | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Check if a thread can wait on the object | ||
| 59 | * @return True if a thread can wait on the object, otherwise false | ||
| 60 | */ | ||
| 61 | bool IsWaitable() const { | ||
| 62 | switch (GetHandleType()) { | ||
| 63 | case HandleType::Event: | ||
| 64 | case HandleType::Thread: | ||
| 65 | case HandleType::Timer: | ||
| 66 | case HandleType::ServerPort: | ||
| 67 | case HandleType::ServerSession: | ||
| 68 | return true; | ||
| 69 | |||
| 70 | case HandleType::Unknown: | ||
| 71 | case HandleType::SharedMemory: | ||
| 72 | case HandleType::Process: | ||
| 73 | case HandleType::AddressArbiter: | ||
| 74 | case HandleType::ResourceLimit: | ||
| 75 | case HandleType::CodeSet: | ||
| 76 | case HandleType::ClientPort: | ||
| 77 | case HandleType::ClientSession: | ||
| 78 | return false; | ||
| 79 | } | ||
| 80 | |||
| 81 | UNREACHABLE(); | ||
| 82 | } | ||
| 83 | |||
| 84 | public: | ||
| 85 | static unsigned int next_object_id; | ||
| 86 | |||
| 87 | private: | ||
| 88 | friend void intrusive_ptr_add_ref(Object*); | ||
| 89 | friend void intrusive_ptr_release(Object*); | ||
| 90 | |||
| 91 | unsigned int ref_count = 0; | ||
| 92 | unsigned int object_id = next_object_id++; | ||
| 93 | }; | ||
| 94 | |||
| 95 | // Special functions used by boost::instrusive_ptr to do automatic ref-counting | ||
| 96 | inline void intrusive_ptr_add_ref(Object* object) { | ||
| 97 | ++object->ref_count; | ||
| 98 | } | ||
| 99 | |||
| 100 | inline void intrusive_ptr_release(Object* object) { | ||
| 101 | if (--object->ref_count == 0) { | ||
| 102 | delete object; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | template <typename T> | ||
| 107 | using SharedPtr = boost::intrusive_ptr<T>; | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Attempts to downcast the given Object pointer to a pointer to T. | ||
| 111 | * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. | ||
| 112 | */ | ||
| 113 | template <typename T> | ||
| 114 | inline SharedPtr<T> DynamicObjectCast(SharedPtr<Object> object) { | ||
| 115 | if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { | ||
| 116 | return boost::static_pointer_cast<T>(std::move(object)); | ||
| 117 | } | ||
| 118 | return nullptr; | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Initialize the kernel with the specified system mode. | 11 | /// Initialize the kernel with the specified system mode. |
| 122 | void Init(u32 system_mode); | 12 | void Init(u32 system_mode); |
| 123 | 13 | ||