Kernel: Convert AddressArbiter to not use Handles
This commit is contained in:
parent
d9b19be1d9
commit
38e7122f23
|
@ -15,25 +15,18 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class AddressArbiter : public Object {
|
ResultVal<SharedPtr<AddressArbiter>> AddressArbiter::Create(std::string name) {
|
||||||
public:
|
SharedPtr<AddressArbiter> address_arbiter(new AddressArbiter);
|
||||||
std::string GetTypeName() const override { return "Arbiter"; }
|
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
||||||
std::string GetName() const override { return name; }
|
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(address_arbiter));
|
||||||
|
|
||||||
static const HandleType HANDLE_TYPE = HandleType::AddressArbiter;
|
address_arbiter->name = std::move(name);
|
||||||
HandleType GetHandleType() const override { return HANDLE_TYPE; }
|
|
||||||
|
|
||||||
std::string name; ///< Name of address arbiter object (optional)
|
return MakeResult<SharedPtr<AddressArbiter>>(std::move(address_arbiter));
|
||||||
};
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, s32 value,
|
||||||
|
u64 nanoseconds) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
// Signal thread(s) waiting for arbitrate address...
|
// Signal thread(s) waiting for arbitrate address...
|
||||||
|
@ -91,18 +84,4 @@ ResultCode ArbitrateAddress(Handle handle, ArbitrationType type, u32 address, s3
|
||||||
return RESULT_SUCCESS;
|
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
|
} // namespace Kernel
|
||||||
|
|
|
@ -26,8 +26,28 @@ enum class ArbitrationType : u32 {
|
||||||
DecrementAndWaitIfLessThanWithTimeout,
|
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
|
} // 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)
|
/// Create an address arbiter (to allocate access to shared resources)
|
||||||
static Result CreateAddressArbiter(u32* arbiter) {
|
static Result CreateAddressArbiter(u32* arbiter) {
|
||||||
Handle handle = Kernel::CreateAddressArbiter();
|
using Kernel::AddressArbiter;
|
||||||
*arbiter = handle;
|
|
||||||
return 0;
|
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
|
/// Arbitrate address
|
||||||
static Result ArbitrateAddress(Handle arbiter, u32 address, u32 type, u32 value, s64 nanoseconds) {
|
static Result ArbitrateAddress(Handle handle, 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,
|
using Kernel::AddressArbiter;
|
||||||
|
|
||||||
|
LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle,
|
||||||
address, type, value);
|
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;
|
address, value, nanoseconds).raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue