k_condition_variable.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/assert.h"
  5. #include "common/common_types.h"
  6. #include "core/hle/kernel/k_scheduler.h"
  7. #include "core/hle/kernel/k_thread.h"
  8. #include "core/hle/kernel/kernel.h"
  9. #include "core/hle/result.h"
  10. namespace Core {
  11. class System;
  12. }
  13. namespace Kernel {
  14. class KConditionVariable {
  15. public:
  16. using ThreadTree = typename KThread::ConditionVariableThreadTreeType;
  17. explicit KConditionVariable(Core::System& system_);
  18. ~KConditionVariable();
  19. // Arbitration
  20. [[nodiscard]] Result SignalToAddress(VAddr addr);
  21. [[nodiscard]] Result WaitForAddress(Handle handle, VAddr addr, u32 value);
  22. // Condition variable
  23. void Signal(u64 cv_key, s32 count);
  24. [[nodiscard]] Result Wait(VAddr addr, u64 key, u32 value, s64 timeout);
  25. private:
  26. void SignalImpl(KThread* thread);
  27. ThreadTree thread_tree;
  28. Core::System& system;
  29. KernelCore& kernel;
  30. };
  31. inline void BeforeUpdatePriority(const KernelCore& kernel, KConditionVariable::ThreadTree* tree,
  32. KThread* thread) {
  33. ASSERT(kernel.GlobalSchedulerContext().IsLocked());
  34. tree->erase(tree->iterator_to(*thread));
  35. }
  36. inline void AfterUpdatePriority(const KernelCore& kernel, KConditionVariable::ThreadTree* tree,
  37. KThread* thread) {
  38. ASSERT(kernel.GlobalSchedulerContext().IsLocked());
  39. tree->insert(*thread);
  40. }
  41. } // namespace Kernel