diff options
author | bunnei <bunneidev@gmail.com> | 2020-12-22 07:36:53 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-01-11 23:23:16 +0100 |
commit | 35c3c078e3c079c0a9192b411e20c71b122ff057 (patch) | |
tree | 572c0b6a47a249a78d658122de32908262ec6a69 /src/core/hle/kernel/k_synchronization_object.h | |
parent | core: hle: kernel: Begin moving common SVC results to its own header. (diff) | |
download | yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.tar yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.tar.gz yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.tar.bz2 yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.tar.lz yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.tar.xz yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.tar.zst yuzu-35c3c078e3c079c0a9192b411e20c71b122ff057.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/k_synchronization_object.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_synchronization_object.h b/src/core/hle/kernel/k_synchronization_object.h new file mode 100644 index 000000000..14d80ebf1 --- /dev/null +++ b/src/core/hle/kernel/k_synchronization_object.h @@ -0,0 +1,58 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <vector> + +#include "core/hle/kernel/object.h" +#include "core/hle/result.h" + +namespace Kernel { + +class KernelCore; +class Synchronization; +class Thread; + +/// Class that represents a Kernel object that a thread can be waiting on +class KSynchronizationObject : public Object { +public: + struct ThreadListNode { + ThreadListNode* next{}; + Thread* thread{}; + }; + + [[nodiscard]] static ResultCode Wait(KernelCore& kernel, s32* out_index, + KSynchronizationObject** objects, const s32 num_objects, + s64 timeout); + + [[nodiscard]] virtual bool IsSignaled() const = 0; + + [[nodiscard]] std::vector<Thread*> GetWaitingThreadsForDebugging() const; + +protected: + explicit KSynchronizationObject(KernelCore& kernel); + virtual ~KSynchronizationObject(); + + void NotifyAvailable(ResultCode result); + void NotifyAvailable() { + return this->NotifyAvailable(RESULT_SUCCESS); + } + +private: + ThreadListNode* thread_list_head{}; + ThreadListNode* thread_list_tail{}; +}; + +// Specialization of DynamicObjectCast for KSynchronizationObjects +template <> +inline std::shared_ptr<KSynchronizationObject> DynamicObjectCast<KSynchronizationObject>( + std::shared_ptr<Object> object) { + if (object != nullptr && object->IsWaitable()) { + return std::static_pointer_cast<KSynchronizationObject>(object); + } + return nullptr; +} + +} // namespace Kernel |