2018-06-21 08:49:43 +02:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-12-11 16:55:38 +01:00
|
|
|
#include <list>
|
2019-12-08 04:09:20 +01:00
|
|
|
#include <memory>
|
2019-12-11 16:55:38 +01:00
|
|
|
#include <unordered_map>
|
2019-03-08 00:48:14 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2018-07-31 14:06:09 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
union ResultCode;
|
2018-06-21 08:49:43 +02:00
|
|
|
|
2019-03-05 18:28:10 +01:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2019-03-05 17:54:06 +01:00
|
|
|
namespace Kernel {
|
2018-06-21 08:49:43 +02:00
|
|
|
|
2019-03-05 17:54:06 +01:00
|
|
|
class Thread;
|
2018-06-22 05:05:34 +02:00
|
|
|
|
2019-03-05 17:54:06 +01:00
|
|
|
class AddressArbiter {
|
|
|
|
public:
|
|
|
|
enum class ArbitrationType {
|
|
|
|
WaitIfLessThan = 0,
|
|
|
|
DecrementAndWaitIfLessThan = 1,
|
|
|
|
WaitIfEqual = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SignalType {
|
|
|
|
Signal = 0,
|
|
|
|
IncrementAndSignalIfEqual = 1,
|
|
|
|
ModifyByWaitingCountAndSignalIfEqual = 2,
|
|
|
|
};
|
|
|
|
|
2019-03-05 18:28:10 +01:00
|
|
|
explicit AddressArbiter(Core::System& system);
|
2019-03-05 17:54:06 +01:00
|
|
|
~AddressArbiter();
|
|
|
|
|
|
|
|
AddressArbiter(const AddressArbiter&) = delete;
|
|
|
|
AddressArbiter& operator=(const AddressArbiter&) = delete;
|
|
|
|
|
|
|
|
AddressArbiter(AddressArbiter&&) = default;
|
|
|
|
AddressArbiter& operator=(AddressArbiter&&) = delete;
|
2018-06-22 05:05:34 +02:00
|
|
|
|
2019-03-08 00:42:44 +01:00
|
|
|
/// Signals an address being waited on with a particular signaling type.
|
|
|
|
ResultCode SignalToAddress(VAddr address, SignalType type, s32 value, s32 num_to_wake);
|
|
|
|
|
|
|
|
/// Waits on an address with a particular arbitration type.
|
|
|
|
ResultCode WaitForAddress(VAddr address, ArbitrationType type, s32 value, s64 timeout_ns);
|
|
|
|
|
2019-12-11 16:55:38 +01:00
|
|
|
/// Removes a thread from the container and resets its address arbiter adress to 0
|
|
|
|
void HandleWakeupThread(std::shared_ptr<Thread> thread);
|
|
|
|
|
2019-03-08 00:42:44 +01:00
|
|
|
private:
|
2019-03-05 17:54:06 +01:00
|
|
|
/// Signals an address being waited on.
|
2019-03-08 00:42:44 +01:00
|
|
|
ResultCode SignalToAddressOnly(VAddr address, s32 num_to_wake);
|
2018-06-22 05:05:34 +02:00
|
|
|
|
2019-03-05 17:54:06 +01:00
|
|
|
/// Signals an address being waited on and increments its value if equal to the value argument.
|
|
|
|
ResultCode IncrementAndSignalToAddressIfEqual(VAddr address, s32 value, s32 num_to_wake);
|
|
|
|
|
|
|
|
/// Signals an address being waited on and modifies its value based on waiting thread count if
|
|
|
|
/// equal to the value argument.
|
|
|
|
ResultCode ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr address, s32 value,
|
|
|
|
s32 num_to_wake);
|
|
|
|
|
|
|
|
/// Waits on an address if the value passed is less than the argument value,
|
|
|
|
/// optionally decrementing.
|
|
|
|
ResultCode WaitForAddressIfLessThan(VAddr address, s32 value, s64 timeout,
|
|
|
|
bool should_decrement);
|
|
|
|
|
|
|
|
/// Waits on an address if the value passed is equal to the argument value.
|
|
|
|
ResultCode WaitForAddressIfEqual(VAddr address, s32 value, s64 timeout);
|
|
|
|
|
|
|
|
// Waits on the given address with a timeout in nanoseconds
|
2019-03-08 00:34:22 +01:00
|
|
|
ResultCode WaitForAddressImpl(VAddr address, s64 timeout);
|
2019-03-05 17:54:06 +01:00
|
|
|
|
2019-12-11 16:55:38 +01:00
|
|
|
/// Wake up num_to_wake (or all) threads in a vector.
|
|
|
|
void WakeThreads(const std::vector<std::shared_ptr<Thread>>& waiting_threads, s32 num_to_wake);
|
|
|
|
|
|
|
|
/// Insert a thread into the address arbiter container
|
|
|
|
void InsertThread(std::shared_ptr<Thread> thread);
|
|
|
|
|
|
|
|
/// Removes a thread from the address arbiter container
|
|
|
|
void RemoveThread(std::shared_ptr<Thread> thread);
|
|
|
|
|
2019-03-05 17:54:06 +01:00
|
|
|
// Gets the threads waiting on an address.
|
2020-02-12 21:07:15 +01:00
|
|
|
std::vector<std::shared_ptr<Thread>> GetThreadsWaitingOnAddress(VAddr address) const;
|
2019-12-11 16:55:38 +01:00
|
|
|
|
|
|
|
/// List of threads waiting for a address arbiter
|
|
|
|
std::unordered_map<VAddr, std::list<std::shared_ptr<Thread>>> arb_threads;
|
2019-03-05 18:28:10 +01:00
|
|
|
|
|
|
|
Core::System& system;
|
2019-03-05 17:54:06 +01:00
|
|
|
};
|
2018-06-22 05:05:34 +02:00
|
|
|
|
2019-03-05 17:54:06 +01:00
|
|
|
} // namespace Kernel
|