1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/assert.h"
#include "common/common_types.h"
#include "core/hle/kernel/k_condition_variable.h"
#include "core/hle/kernel/svc_types.h"
union Result;
namespace Core {
class System;
}
namespace Kernel {
class KernelCore;
class KAddressArbiter {
public:
using ThreadTree = KConditionVariable::ThreadTree;
explicit KAddressArbiter(Core::System& system);
~KAddressArbiter();
Result SignalToAddress(uint64_t addr, Svc::SignalType type, s32 value, s32 count) {
switch (type) {
case Svc::SignalType::Signal:
R_RETURN(this->Signal(addr, count));
case Svc::SignalType::SignalAndIncrementIfEqual:
R_RETURN(this->SignalAndIncrementIfEqual(addr, value, count));
case Svc::SignalType::SignalAndModifyByWaitingCountIfEqual:
R_RETURN(this->SignalAndModifyByWaitingCountIfEqual(addr, value, count));
default:
UNREACHABLE();
}
}
Result WaitForAddress(uint64_t addr, Svc::ArbitrationType type, s32 value, s64 timeout) {
switch (type) {
case Svc::ArbitrationType::WaitIfLessThan:
R_RETURN(WaitIfLessThan(addr, value, false, timeout));
case Svc::ArbitrationType::DecrementAndWaitIfLessThan:
R_RETURN(WaitIfLessThan(addr, value, true, timeout));
case Svc::ArbitrationType::WaitIfEqual:
R_RETURN(WaitIfEqual(addr, value, timeout));
default:
UNREACHABLE();
}
}
private:
Result Signal(uint64_t addr, s32 count);
Result SignalAndIncrementIfEqual(uint64_t addr, s32 value, s32 count);
Result SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32 value, s32 count);
Result WaitIfLessThan(uint64_t addr, s32 value, bool decrement, s64 timeout);
Result WaitIfEqual(uint64_t addr, s32 value, s64 timeout);
private:
ThreadTree m_tree;
Core::System& m_system;
KernelCore& m_kernel;
};
} // namespace Kernel
|