mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-09-09 16:19:09 +01:00
Kernel: Convert AddressArbiter to not use Handles
This commit is contained in:
parent
d9b19be1d9
commit
38e7122f23
3 changed files with 55 additions and 38 deletions
|
@ -15,25 +15,18 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class AddressArbiter : public Object {
|
||||
public:
|
||||
std::string GetTypeName() const override { return "Arbiter"; }
|
||||
std::string GetName() const override { return name; }
|
||||
ResultVal<SharedPtr<AddressArbiter>> AddressArbiter::Create(std::string name) {
|
||||
SharedPtr<AddressArbiter> address_arbiter(new AddressArbiter);
|
||||
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(address_arbiter));
|
||||
|
||||
static const HandleType HANDLE_TYPE = HandleType::AddressArbiter;
|
||||
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
||||
address_arbiter->name = std::move(name);
|
||||
|
||||
std::string name; ///< Name of address arbiter object (optional)
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ResultCode ArbitrateAddress(Handle handle, ArbitrationType type, u32 address, s32 value, u64 nanoseconds) {
|
||||
AddressArbiter* object = Kernel::g_handle_table.Get<AddressArbiter>(handle).get();
|
||||
|
||||
if (object == nullptr)
|
||||
return InvalidHandle(ErrorModule::Kernel);
|
||||
return MakeResult<SharedPtr<AddressArbiter>>(std::move(address_arbiter));
|
||||
}
|
||||
|
||||
ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, s32 value,
|
||||
u64 nanoseconds) {
|
||||
switch (type) {
|
||||
|
||||
// Signal thread(s) waiting for arbitrate address...
|
||||
|
@ -91,18 +84,4 @@ ResultCode ArbitrateAddress(Handle handle, ArbitrationType type, u32 address, s3
|
|||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static AddressArbiter* CreateAddressArbiter(Handle& handle, const std::string& name) {
|
||||
AddressArbiter* address_arbiter = new AddressArbiter;
|
||||
// TOOD(yuriks): Fix error reporting
|
||||
handle = Kernel::g_handle_table.Create(address_arbiter).ValueOr(INVALID_HANDLE);
|
||||
address_arbiter->name = name;
|
||||
return address_arbiter;
|
||||
}
|
||||
|
||||
Handle CreateAddressArbiter(const std::string& name) {
|
||||
Handle handle;
|
||||
CreateAddressArbiter(handle, name);
|
||||
return handle;
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -26,8 +26,28 @@ enum class ArbitrationType : u32 {
|
|||
DecrementAndWaitIfLessThanWithTimeout,
|
||||
};
|
||||
|
||||
ResultCode ArbitrateAddress(Handle handle, ArbitrationType type, u32 address, s32 value, u64 nanoseconds);
|
||||
class AddressArbiter : public Object {
|
||||
public:
|
||||
/**
|
||||
* Creates an address arbiter.
|
||||
*
|
||||
* @param name Optional name used for debugging.
|
||||
* @returns The created AddressArbiter.
|
||||
*/
|
||||
static ResultVal<SharedPtr<AddressArbiter>> Create(std::string name = "Unknown");
|
||||
|
||||
Handle CreateAddressArbiter(const std::string& name = "Unknown");
|
||||
std::string GetTypeName() const override { return "Arbiter"; }
|
||||
std::string GetName() const override { return name; }
|
||||
|
||||
static const HandleType HANDLE_TYPE = HandleType::AddressArbiter;
|
||||
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
||||
|
||||
std::string name; ///< Name of address arbiter object (optional)
|
||||
|
||||
ResultCode ArbitrateAddress(ArbitrationType type, VAddr address, s32 value, u64 nanoseconds);
|
||||
|
||||
private:
|
||||
AddressArbiter() = default;
|
||||
};
|
||||
|
||||
} // namespace FileSys
|
||||
|
|
|
@ -247,16 +247,34 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count,
|
|||
|
||||
/// Create an address arbiter (to allocate access to shared resources)
|
||||
static Result CreateAddressArbiter(u32* arbiter) {
|
||||
Handle handle = Kernel::CreateAddressArbiter();
|
||||
*arbiter = handle;
|
||||
return 0;
|
||||
using Kernel::AddressArbiter;
|
||||
|
||||
ResultVal<SharedPtr<AddressArbiter>> arbiter_res = AddressArbiter::Create();
|
||||
if (arbiter_res.Failed())
|
||||
return arbiter_res.Code().raw;
|
||||
|
||||
ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*arbiter_res);
|
||||
if (handle_res.Failed())
|
||||
return handle_res.Code().raw;
|
||||
|
||||
LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res);
|
||||
|
||||
*arbiter = *handle_res;
|
||||
return RESULT_SUCCESS.raw;
|
||||
}
|
||||
|
||||
/// Arbitrate address
|
||||
static Result ArbitrateAddress(Handle arbiter, u32 address, u32 type, u32 value, s64 nanoseconds) {
|
||||
LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", arbiter,
|
||||
static Result ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) {
|
||||
using Kernel::AddressArbiter;
|
||||
|
||||
LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle,
|
||||
address, type, value);
|
||||
return Kernel::ArbitrateAddress(arbiter, static_cast<Kernel::ArbitrationType>(type),
|
||||
|
||||
SharedPtr<AddressArbiter> arbiter = Kernel::g_handle_table.Get<AddressArbiter>(handle);
|
||||
if (arbiter == nullptr)
|
||||
return InvalidHandle(ErrorModule::Kernel).raw;
|
||||
|
||||
return arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type),
|
||||
address, value, nanoseconds).raw;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue