diff options
| author | 2015-01-18 14:33:11 -0500 | |
|---|---|---|
| committer | 2015-01-21 20:47:46 -0500 | |
| commit | 9412996c8f86f5da5a9052f7533b05e9780c4eb0 (patch) | |
| tree | af0ddc0b464d92c7e13664f6f435c5de6c36301a /src/core/hle/kernel/kernel.h | |
| parent | SVC: Removed a Sleep that made no sense (diff) | |
| download | yuzu-9412996c8f86f5da5a9052f7533b05e9780c4eb0.tar.gz yuzu-9412996c8f86f5da5a9052f7533b05e9780c4eb0.tar.xz yuzu-9412996c8f86f5da5a9052f7533b05e9780c4eb0.zip | |
Kernel: Moved Wait and Acquire to WaitObject, added way to retrieve a WaitObject safely.
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 5bf9a2bfc..a9a893f41 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -60,26 +60,34 @@ class Object : NonCopyable { | |||
| 60 | public: | 60 | public: |
| 61 | virtual ~Object() {} | 61 | virtual ~Object() {} |
| 62 | Handle GetHandle() const { return handle; } | 62 | Handle GetHandle() const { return handle; } |
| 63 | |||
| 63 | virtual std::string GetTypeName() const { return "[BAD KERNEL OBJECT TYPE]"; } | 64 | virtual std::string GetTypeName() const { return "[BAD KERNEL OBJECT TYPE]"; } |
| 64 | virtual std::string GetName() const { return "[UNKNOWN KERNEL OBJECT]"; } | 65 | virtual std::string GetName() const { return "[UNKNOWN KERNEL OBJECT]"; } |
| 65 | virtual Kernel::HandleType GetHandleType() const = 0; | 66 | virtual Kernel::HandleType GetHandleType() const = 0; |
| 66 | 67 | ||
| 67 | /** | 68 | /** |
| 68 | * Check if this object is available | 69 | * Check if a thread can wait on the object |
| 69 | * @return True if the current thread should wait due to this object being unavailable | 70 | * @return True if a thread can wait on the object, otherwise false |
| 70 | */ | 71 | */ |
| 71 | virtual ResultVal<bool> Wait() { | 72 | bool IsWaitable() const { |
| 72 | LOG_ERROR(Kernel, "(UNIMPLEMENTED)"); | 73 | switch (GetHandleType()) { |
| 73 | return UnimplementedFunction(ErrorModule::Kernel); | 74 | case HandleType::Event: |
| 74 | } | 75 | case HandleType::Mutex: |
| 76 | case HandleType::Thread: | ||
| 77 | case HandleType::Semaphore: | ||
| 78 | case HandleType::Timer: | ||
| 79 | return true; | ||
| 80 | |||
| 81 | case HandleType::Unknown: | ||
| 82 | case HandleType::Port: | ||
| 83 | case HandleType::SharedMemory: | ||
| 84 | case HandleType::Redirection: | ||
| 85 | case HandleType::Process: | ||
| 86 | case HandleType::AddressArbiter: | ||
| 87 | return false; | ||
| 88 | } | ||
| 75 | 89 | ||
| 76 | /** | 90 | return false; |
| 77 | * Acquire/lock the this object if it is available | ||
| 78 | * @return True if we were able to acquire this object, otherwise false | ||
| 79 | */ | ||
| 80 | virtual ResultVal<bool> Acquire() { | ||
| 81 | LOG_ERROR(Kernel, "(UNIMPLEMENTED)"); | ||
| 82 | return UnimplementedFunction(ErrorModule::Kernel); | ||
| 83 | } | 91 | } |
| 84 | 92 | ||
| 85 | private: | 93 | private: |
| @@ -108,6 +116,24 @@ class WaitObject : public Object { | |||
| 108 | public: | 116 | public: |
| 109 | 117 | ||
| 110 | /** | 118 | /** |
| 119 | * Check if this object is available | ||
| 120 | * @return True if the current thread should wait due to this object being unavailable | ||
| 121 | */ | ||
| 122 | virtual ResultVal<bool> Wait() { | ||
| 123 | LOG_ERROR(Kernel, "(UNIMPLEMENTED)"); | ||
| 124 | return UnimplementedFunction(ErrorModule::Kernel); | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Acquire/lock the this object if it is available | ||
| 129 | * @return True if we were able to acquire this object, otherwise false | ||
| 130 | */ | ||
| 131 | virtual ResultVal<bool> Acquire() { | ||
| 132 | LOG_ERROR(Kernel, "(UNIMPLEMENTED)"); | ||
| 133 | return UnimplementedFunction(ErrorModule::Kernel); | ||
| 134 | } | ||
| 135 | |||
| 136 | /** | ||
| 111 | * Add a thread to wait on this object | 137 | * Add a thread to wait on this object |
| 112 | * @param thread Pointer to thread to add | 138 | * @param thread Pointer to thread to add |
| 113 | */ | 139 | */ |
| @@ -186,14 +212,14 @@ public: | |||
| 186 | 212 | ||
| 187 | /** | 213 | /** |
| 188 | * Looks up a handle. | 214 | * Looks up a handle. |
| 189 | * @returns Pointer to the looked-up object, or `nullptr` if the handle is not valid. | 215 | * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid. |
| 190 | */ | 216 | */ |
| 191 | SharedPtr<Object> GetGeneric(Handle handle) const; | 217 | SharedPtr<Object> GetGeneric(Handle handle) const; |
| 192 | 218 | ||
| 193 | /** | 219 | /** |
| 194 | * Looks up a handle while verifying its type. | 220 | * Looks up a handle while verifying its type. |
| 195 | * @returns Pointer to the looked-up object, or `nullptr` if the handle is not valid or its | 221 | * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid or its |
| 196 | * type differs from the handle type `T::HANDLE_TYPE`. | 222 | * type differs from the handle type `T::HANDLE_TYPE`. |
| 197 | */ | 223 | */ |
| 198 | template <class T> | 224 | template <class T> |
| 199 | SharedPtr<T> Get(Handle handle) const { | 225 | SharedPtr<T> Get(Handle handle) const { |
| @@ -204,6 +230,19 @@ public: | |||
| 204 | return nullptr; | 230 | return nullptr; |
| 205 | } | 231 | } |
| 206 | 232 | ||
| 233 | /** | ||
| 234 | * Looks up a handle while verifying that it is an object that a thread can wait on | ||
| 235 | * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid or it is | ||
| 236 | * not a waitable object. | ||
| 237 | */ | ||
| 238 | SharedPtr<WaitObject> GetWaitObject(Handle handle) const { | ||
| 239 | SharedPtr<Object> object = GetGeneric(handle); | ||
| 240 | if (object != nullptr && object->IsWaitable()) { | ||
| 241 | return boost::static_pointer_cast<WaitObject>(std::move(object)); | ||
| 242 | } | ||
| 243 | return nullptr; | ||
| 244 | } | ||
| 245 | |||
| 207 | /// Closes all handles held in this table. | 246 | /// Closes all handles held in this table. |
| 208 | void Clear(); | 247 | void Clear(); |
| 209 | 248 | ||