summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_condition_variable.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-12-29 08:45:28 +0100
committerbunnei <bunneidev@gmail.com>2021-01-11 23:23:16 +0100
commitb4e6d6c38586eaa5aab7f7df3f9d958755a517c2 (patch)
tree8298e102b21223af6b174525844917acff2afabb /src/core/hle/kernel/k_condition_variable.h
parentcore: hle: kernel: Begin moving common SVC defintions to its own header. (diff)
downloadyuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.tar
yuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.tar.gz
yuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.tar.bz2
yuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.tar.lz
yuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.tar.xz
yuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.tar.zst
yuzu-b4e6d6c38586eaa5aab7f7df3f9d958755a517c2.zip
Diffstat (limited to 'src/core/hle/kernel/k_condition_variable.h')
-rw-r--r--src/core/hle/kernel/k_condition_variable.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_condition_variable.h b/src/core/hle/kernel/k_condition_variable.h
new file mode 100644
index 000000000..98ed5b323
--- /dev/null
+++ b/src/core/hle/kernel/k_condition_variable.h
@@ -0,0 +1,59 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/assert.h"
+#include "common/common_types.h"
+
+#include "core/hle/kernel/k_scheduler.h"
+#include "core/hle/kernel/kernel.h"
+#include "core/hle/kernel/thread.h"
+#include "core/hle/result.h"
+
+namespace Core {
+class System;
+}
+
+namespace Kernel {
+
+class KConditionVariable {
+public:
+ using ThreadTree = typename Thread::ConditionVariableThreadTreeType;
+
+ explicit KConditionVariable(Core::System& system_);
+ ~KConditionVariable();
+
+ // Arbitration
+ [[nodiscard]] ResultCode SignalToAddress(VAddr addr);
+ [[nodiscard]] ResultCode WaitForAddress(Handle handle, VAddr addr, u32 value);
+
+ // Condition variable
+ void Signal(u64 cv_key, s32 count);
+ [[nodiscard]] ResultCode Wait(VAddr addr, u64 key, u32 value, s64 timeout);
+
+private:
+ [[nodiscard]] Thread* SignalImpl(Thread* thread);
+
+ ThreadTree thread_tree;
+
+ Core::System& system;
+ KernelCore& kernel;
+};
+
+inline void BeforeUpdatePriority(const KernelCore& kernel, KConditionVariable::ThreadTree* tree,
+ Thread* thread) {
+ ASSERT(kernel.GlobalSchedulerContext().IsLocked());
+
+ tree->erase(tree->iterator_to(*thread));
+}
+
+inline void AfterUpdatePriority(const KernelCore& kernel, KConditionVariable::ThreadTree* tree,
+ Thread* thread) {
+ ASSERT(kernel.GlobalSchedulerContext().IsLocked());
+
+ tree->insert(*thread);
+}
+
+} // namespace Kernel