2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-12-29 08:45:28 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
|
|
|
|
#include "core/hle/kernel/k_scheduler.h"
|
2020-12-31 08:01:08 +01:00
|
|
|
#include "core/hle/kernel/k_thread.h"
|
2023-03-18 02:26:04 +01:00
|
|
|
#include "core/hle/kernel/k_typed_address.h"
|
2020-12-29 08:45:28 +01:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/result.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class KConditionVariable {
|
|
|
|
public:
|
2020-12-31 08:01:08 +01:00
|
|
|
using ThreadTree = typename KThread::ConditionVariableThreadTreeType;
|
2020-12-29 08:45:28 +01:00
|
|
|
|
2023-03-07 02:53:58 +01:00
|
|
|
explicit KConditionVariable(Core::System& system);
|
2020-12-29 08:45:28 +01:00
|
|
|
~KConditionVariable();
|
|
|
|
|
2023-10-21 22:47:43 +02:00
|
|
|
// Arbitration.
|
|
|
|
static Result SignalToAddress(KernelCore& kernel, KProcessAddress addr);
|
|
|
|
static Result WaitForAddress(KernelCore& kernel, Handle handle, KProcessAddress addr,
|
|
|
|
u32 value);
|
2020-12-29 08:45:28 +01:00
|
|
|
|
2023-10-21 22:47:43 +02:00
|
|
|
// Condition variable.
|
2020-12-29 08:45:28 +01:00
|
|
|
void Signal(u64 cv_key, s32 count);
|
2023-03-18 02:26:04 +01:00
|
|
|
Result Wait(KProcessAddress addr, u64 key, u32 value, s64 timeout);
|
2020-12-29 08:45:28 +01:00
|
|
|
|
|
|
|
private:
|
2021-11-10 07:06:49 +01:00
|
|
|
void SignalImpl(KThread* thread);
|
2020-12-29 08:45:28 +01:00
|
|
|
|
2023-03-07 02:53:58 +01:00
|
|
|
private:
|
|
|
|
Core::System& m_system;
|
|
|
|
KernelCore& m_kernel;
|
|
|
|
ThreadTree m_tree{};
|
2020-12-29 08:45:28 +01:00
|
|
|
};
|
|
|
|
|
2023-03-07 22:11:50 +01:00
|
|
|
inline void BeforeUpdatePriority(KernelCore& kernel, KConditionVariable::ThreadTree* tree,
|
2020-12-31 08:01:08 +01:00
|
|
|
KThread* thread) {
|
2023-03-07 22:11:50 +01:00
|
|
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
2020-12-29 08:45:28 +01:00
|
|
|
|
|
|
|
tree->erase(tree->iterator_to(*thread));
|
|
|
|
}
|
|
|
|
|
2023-03-07 22:11:50 +01:00
|
|
|
inline void AfterUpdatePriority(KernelCore& kernel, KConditionVariable::ThreadTree* tree,
|
2020-12-31 08:01:08 +01:00
|
|
|
KThread* thread) {
|
2023-03-07 22:11:50 +01:00
|
|
|
ASSERT(KScheduler::IsSchedulerLockedByCurrentThread(kernel));
|
2020-12-29 08:45:28 +01:00
|
|
|
|
|
|
|
tree->insert(*thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Kernel
|