From 734be98966d07645811f216a6df34ceeb9457edf Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Thu, 11 Oct 2018 15:19:45 -0400 Subject: [PATCH] Kernel: pass Kernel reference into AddressArbiter --- src/core/hle/kernel/address_arbiter.cpp | 7 ++++--- src/core/hle/kernel/address_arbiter.h | 12 +++--------- src/core/hle/kernel/kernel.h | 15 +++++++++++++++ src/core/hle/kernel/object.h | 7 +------ src/core/hle/kernel/svc.cpp | 2 +- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 1dc005554b..ad2805cbf7 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp @@ -7,6 +7,7 @@ #include "common/logging/log.h" #include "core/hle/kernel/address_arbiter.h" #include "core/hle/kernel/errors.h" +#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/thread.h" #include "core/memory.h" @@ -64,11 +65,11 @@ SharedPtr AddressArbiter::ResumeHighestPriorityThread(VAddr address) { return thread; } -AddressArbiter::AddressArbiter() {} +AddressArbiter::AddressArbiter(KernelSystem& kernel) {} AddressArbiter::~AddressArbiter() {} -SharedPtr AddressArbiter::Create(std::string name) { - SharedPtr address_arbiter(new AddressArbiter); +SharedPtr KernelSystem::CreateAddressArbiter(std::string name) { + SharedPtr address_arbiter(new AddressArbiter(*this)); address_arbiter->name = std::move(name); diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h index cf27618193..cdfa64ec21 100644 --- a/src/core/hle/kernel/address_arbiter.h +++ b/src/core/hle/kernel/address_arbiter.h @@ -31,14 +31,6 @@ enum class ArbitrationType : u32 { class AddressArbiter final : public Object { public: - /** - * Creates an address arbiter. - * - * @param name Optional name used for debugging. - * @returns The created AddressArbiter. - */ - static SharedPtr Create(std::string name = "Unknown"); - std::string GetTypeName() const override { return "Arbiter"; } @@ -57,7 +49,7 @@ public: s32 value, u64 nanoseconds); private: - AddressArbiter(); + explicit AddressArbiter(KernelSystem& kernel); ~AddressArbiter() override; /// Puts the thread to wait on the specified arbitration address under this address arbiter. @@ -72,6 +64,8 @@ private: /// Threads waiting for the address arbiter to be signaled. std::vector> waiting_threads; + + friend class KernelSystem; }; } // namespace Kernel diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index c19cdc92d5..12a5a8cef3 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -4,14 +4,29 @@ #pragma once +#include +#include #include "common/common_types.h" namespace Kernel { +class AddressArbiter; + +template +using SharedPtr = boost::intrusive_ptr; + class KernelSystem { public: explicit KernelSystem(u32 system_mode); ~KernelSystem(); + + /** + * Creates an address arbiter. + * + * @param name Optional name used for debugging. + * @returns The created AddressArbiter. + */ + SharedPtr CreateAddressArbiter(std::string name = "Unknown"); }; } // namespace Kernel diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h index fbacf93593..6bc6fe00dd 100644 --- a/src/core/hle/kernel/object.h +++ b/src/core/hle/kernel/object.h @@ -6,10 +6,8 @@ #include #include - -#include - #include "common/common_types.h" +#include "core/hle/kernel/kernel.h" namespace Kernel { @@ -88,9 +86,6 @@ inline void intrusive_ptr_release(Object* object) { } } -template -using SharedPtr = boost::intrusive_ptr; - /** * Attempts to downcast the given Object pointer to a pointer to T. * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index a5889d6c82..dcfca5c53d 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -615,7 +615,7 @@ static ResultCode ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_ /// Create an address arbiter (to allocate access to shared resources) static ResultCode CreateAddressArbiter(Handle* out_handle) { - SharedPtr arbiter = AddressArbiter::Create(); + SharedPtr arbiter = Core::System::GetInstance().Kernel().CreateAddressArbiter(); CASCADE_RESULT(*out_handle, g_handle_table.Create(std::move(arbiter))); LOG_TRACE(Kernel_SVC, "returned handle=0x{:08X}", *out_handle); return RESULT_SUCCESS;