summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp39
-rw-r--r--src/core/hle/kernel/address_arbiter.h24
-rw-r--r--src/core/hle/svc.cpp30
3 files changed, 55 insertions, 38 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index 2a66f8dd5..2d01e2ef5 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -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
diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h
index 81084bdc8..536f0f017 100644
--- a/src/core/hle/kernel/address_arbiter.h
+++ b/src/core/hle/kernel/address_arbiter.h
@@ -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
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 6cbe38bc3..b093d0368 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -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;
}