2014-07-07 03:15:40 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 05:38:14 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-07-07 03:15:40 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-11-08 23:07:22 +00:00
|
|
|
#include <vector>
|
2014-07-07 03:15:40 +00:00
|
|
|
#include "common/common_types.h"
|
2018-08-02 02:40:00 +00:00
|
|
|
#include "core/hle/kernel/object.h"
|
2017-05-29 23:45:42 +00:00
|
|
|
#include "core/hle/result.h"
|
2014-07-07 03:15:40 +00:00
|
|
|
|
|
|
|
// Address arbiters are an underlying kernel synchronization object that can be created/used via
|
|
|
|
// supervisor calls (SVCs). They function as sort of a global lock. Typically, games/other CTR
|
|
|
|
// applications use them as an underlying mechanism to implement thread-safe barriers, events, and
|
2017-11-08 23:07:22 +00:00
|
|
|
// semaphores.
|
2014-07-07 03:15:40 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Kernel namespace
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2017-11-08 23:07:22 +00:00
|
|
|
class Thread;
|
|
|
|
|
2014-07-07 03:15:40 +00:00
|
|
|
enum class ArbitrationType : u32 {
|
|
|
|
Signal,
|
|
|
|
WaitIfLessThan,
|
|
|
|
DecrementAndWaitIfLessThan,
|
|
|
|
WaitIfLessThanWithTimeout,
|
|
|
|
DecrementAndWaitIfLessThanWithTimeout,
|
|
|
|
};
|
|
|
|
|
2015-01-27 04:40:21 +00:00
|
|
|
class AddressArbiter final : public Object {
|
2015-01-11 16:46:49 +00:00
|
|
|
public:
|
2019-03-23 20:04:19 +00:00
|
|
|
explicit AddressArbiter(KernelSystem& kernel);
|
|
|
|
~AddressArbiter() override;
|
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
std::string GetTypeName() const override {
|
|
|
|
return "Arbiter";
|
|
|
|
}
|
|
|
|
std::string GetName() const override {
|
|
|
|
return name;
|
|
|
|
}
|
2015-01-11 16:46:49 +00:00
|
|
|
|
|
|
|
static const HandleType HANDLE_TYPE = HandleType::AddressArbiter;
|
2016-09-18 00:38:01 +00:00
|
|
|
HandleType GetHandleType() const override {
|
|
|
|
return HANDLE_TYPE;
|
|
|
|
}
|
2015-01-11 16:46:49 +00:00
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
std::string name; ///< Name of address arbiter object (optional)
|
2015-01-11 16:46:49 +00:00
|
|
|
|
2019-03-23 20:04:19 +00:00
|
|
|
ResultCode ArbitrateAddress(std::shared_ptr<Thread> thread, ArbitrationType type, VAddr address,
|
2017-11-08 23:07:22 +00:00
|
|
|
s32 value, u64 nanoseconds);
|
2015-01-11 16:46:49 +00:00
|
|
|
|
|
|
|
private:
|
2018-11-21 20:04:31 +00:00
|
|
|
KernelSystem& kernel;
|
|
|
|
|
2017-11-08 23:07:22 +00:00
|
|
|
/// Puts the thread to wait on the specified arbitration address under this address arbiter.
|
2019-03-23 20:04:19 +00:00
|
|
|
void WaitThread(std::shared_ptr<Thread> thread, VAddr wait_address);
|
2017-11-08 23:07:22 +00:00
|
|
|
|
|
|
|
/// Resume all threads found to be waiting on the address under this address arbiter
|
|
|
|
void ResumeAllThreads(VAddr address);
|
|
|
|
|
|
|
|
/// Resume one thread found to be waiting on the address under this address arbiter and return
|
|
|
|
/// the resumed thread.
|
2019-03-23 20:04:19 +00:00
|
|
|
std::shared_ptr<Thread> ResumeHighestPriorityThread(VAddr address);
|
2017-11-08 23:07:22 +00:00
|
|
|
|
|
|
|
/// Threads waiting for the address arbiter to be signaled.
|
2019-03-23 20:04:19 +00:00
|
|
|
std::vector<std::shared_ptr<Thread>> waiting_threads;
|
2015-01-11 16:46:49 +00:00
|
|
|
};
|
2014-07-07 03:15:40 +00:00
|
|
|
|
2017-11-08 23:07:22 +00:00
|
|
|
} // namespace Kernel
|