From 88a4a808c688eeabb136e9b45223a0e9c95896bc Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sun, 1 Feb 2015 00:14:40 -0200 Subject: [PATCH] Kernel: Stop creating useless Handles during object creation They're finally unnecessary, and will stop cluttering the application's handle table. --- src/core/hle/kernel/address_arbiter.cpp | 6 ++---- src/core/hle/kernel/address_arbiter.h | 2 +- src/core/hle/kernel/event.cpp | 6 ++---- src/core/hle/kernel/event.h | 2 +- src/core/hle/kernel/mutex.cpp | 6 ++---- src/core/hle/kernel/mutex.h | 2 +- src/core/hle/kernel/semaphore.cpp | 2 -- src/core/hle/kernel/shared_memory.cpp | 8 +++----- src/core/hle/kernel/shared_memory.h | 2 +- src/core/hle/kernel/thread.cpp | 8 -------- src/core/hle/kernel/timer.cpp | 7 +++---- src/core/hle/kernel/timer.h | 2 +- src/core/hle/service/apt_u.cpp | 8 ++++---- src/core/hle/service/dsp_dsp.cpp | 3 +-- src/core/hle/service/gsp_gpu.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 12 ++++++------ src/core/hle/service/srv.cpp | 2 +- src/core/hle/svc.cpp | 18 +++++++++++------- 18 files changed, 41 insertions(+), 57 deletions(-) diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 2084f24cc4..42f8ce2d90 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp @@ -18,14 +18,12 @@ namespace Kernel { AddressArbiter::AddressArbiter() {} AddressArbiter::~AddressArbiter() {} -ResultVal> AddressArbiter::Create(std::string name) { +SharedPtr AddressArbiter::Create(std::string name) { SharedPtr address_arbiter(new AddressArbiter); - // TOOD(yuriks): Don't create Handle (see Thread::Create()) - CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(address_arbiter)); address_arbiter->name = std::move(name); - return MakeResult>(std::move(address_arbiter)); + return address_arbiter; } ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, s32 value, diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h index a616d840f6..8f6a1a8dfd 100644 --- a/src/core/hle/kernel/address_arbiter.h +++ b/src/core/hle/kernel/address_arbiter.h @@ -34,7 +34,7 @@ public: * @param name Optional name used for debugging. * @returns The created AddressArbiter. */ - static ResultVal> Create(std::string name = "Unknown"); + static SharedPtr Create(std::string name = "Unknown"); std::string GetTypeName() const override { return "Arbiter"; } std::string GetName() const override { return name; } diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index 3796fbb746..898e1c98fd 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -17,16 +17,14 @@ namespace Kernel { Event::Event() {} Event::~Event() {} -ResultVal> Event::Create(ResetType reset_type, std::string name) { +SharedPtr Event::Create(ResetType reset_type, std::string name) { SharedPtr evt(new Event); - // TOOD(yuriks): Don't create Handle (see Thread::Create()) - CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(evt)); evt->signaled = false; evt->reset_type = evt->intitial_reset_type = reset_type; evt->name = std::move(name); - return MakeResult>(evt); + return evt; } bool Event::ShouldWait() { diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index 6f88afb3ea..fba960d2a1 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -18,7 +18,7 @@ public: * @param reset_type ResetType describing how to create event * @param name Optional name of event */ - static ResultVal> Create(ResetType reset_type, std::string name = "Unknown"); + static SharedPtr Create(ResetType reset_type, std::string name = "Unknown"); std::string GetTypeName() const override { return "Event"; } std::string GetName() const override { return name; } diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 7c634f9bd0..9f7166ca43 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -41,10 +41,8 @@ void ReleaseThreadMutexes(Thread* thread) { Mutex::Mutex() {} Mutex::~Mutex() {} -ResultVal> Mutex::Create(bool initial_locked, std::string name) { +SharedPtr Mutex::Create(bool initial_locked, std::string name) { SharedPtr mutex(new Mutex); - // TOOD(yuriks): Don't create Handle (see Thread::Create()) - CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(mutex)); mutex->initial_locked = initial_locked; mutex->locked = false; @@ -55,7 +53,7 @@ ResultVal> Mutex::Create(bool initial_locked, std::string name) if (initial_locked) mutex->Acquire(); - return MakeResult>(mutex); + return mutex; } bool Mutex::ShouldWait() { diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h index cdd79e265a..548403614d 100644 --- a/src/core/hle/kernel/mutex.h +++ b/src/core/hle/kernel/mutex.h @@ -22,7 +22,7 @@ public: * @param name Optional name of mutex * @return Pointer to new Mutex object */ - static ResultVal> Create(bool initial_locked, std::string name = "Unknown"); + static SharedPtr Create(bool initial_locked, std::string name = "Unknown"); std::string GetTypeName() const override { return "Mutex"; } std::string GetName() const override { return name; } diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp index 234d60d850..c8cf8b9a22 100644 --- a/src/core/hle/kernel/semaphore.cpp +++ b/src/core/hle/kernel/semaphore.cpp @@ -21,8 +21,6 @@ ResultVal> Semaphore::Create(s32 initial_count, s32 max_cou ErrorSummary::WrongArgument, ErrorLevel::Permanent); SharedPtr semaphore(new Semaphore); - // TOOD(yuriks): Don't create Handle (see Thread::Create()) - CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(semaphore)); // When the semaphore is created, some slots are reserved for other threads, // and the rest is reserved for the caller thread diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index c429bb9b40..4211fcf043 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -12,14 +12,12 @@ namespace Kernel { SharedMemory::SharedMemory() {} SharedMemory::~SharedMemory() {} -ResultVal> SharedMemory::Create(std::string name) { +SharedPtr SharedMemory::Create(std::string name) { SharedPtr shared_memory(new SharedMemory); - // TOOD(yuriks): Don't create Handle (see Thread::Create()) - CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(shared_memory)); - shared_memory->name = std::move(name); - return MakeResult>(std::move(shared_memory)); + + return shared_memory; } ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index d9e741d207..5833b411ce 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -29,7 +29,7 @@ public: * Creates a shared memory object * @param name Optional object name, used only for debugging purposes. */ - static ResultVal> Create(std::string name = "Unknown"); + static SharedPtr Create(std::string name = "Unknown"); std::string GetTypeName() const override { return "SharedMemory"; } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f092916dde..3987f96080 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -368,14 +368,6 @@ ResultVal> Thread::Create(std::string name, VAddr entry_point, SharedPtr thread(new Thread); - // TODO(yuriks): Thread requires a handle to be inserted into the various scheduling queues for - // the time being. Create a handle here, it will be copied to the handle field in - // the object and use by the rest of the code. This should be removed when other - // code doesn't rely on the handle anymore. - ResultVal handle = Kernel::g_handle_table.Create(thread); - if (handle.Failed()) - return handle.Code(); - thread_list.push_back(thread); thread_ready_queue.prepare(priority); diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 7c3cdc0d00..4352fc99c9 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -20,10 +20,8 @@ static Kernel::HandleTable timer_callback_handle_table; Timer::Timer() {} Timer::~Timer() {} -ResultVal> Timer::Create(ResetType reset_type, std::string name) { +SharedPtr Timer::Create(ResetType reset_type, std::string name) { SharedPtr timer(new Timer); - // TOOD(yuriks): Don't create Handle (see Thread::Create()) - CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(timer)); timer->reset_type = reset_type; timer->signaled = false; @@ -31,7 +29,8 @@ ResultVal> Timer::Create(ResetType reset_type, std::string name timer->initial_delay = 0; timer->interval_delay = 0; timer->callback_handle = timer_callback_handle_table.Create(timer).MoveFrom(); - return MakeResult>(timer); + + return timer; } bool Timer::ShouldWait() { diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h index e217d6dae7..540e4e187e 100644 --- a/src/core/hle/kernel/timer.h +++ b/src/core/hle/kernel/timer.h @@ -19,7 +19,7 @@ public: * @param name Optional name of timer * @return The created Timer */ - static ResultVal> Create(ResetType reset_type, std::string name = "Unknown"); + static SharedPtr Create(ResetType reset_type, std::string name = "Unknown"); std::string GetTypeName() const override { return "Timer"; } std::string GetName() const override { return name; } diff --git a/src/core/hle/service/apt_u.cpp b/src/core/hle/service/apt_u.cpp index 1e6f1f78c6..ccfd045911 100644 --- a/src/core/hle/service/apt_u.cpp +++ b/src/core/hle/service/apt_u.cpp @@ -69,8 +69,8 @@ void Initialize(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); // TODO(bunnei): Check if these are created in Initialize or on APT process startup. - notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification").MoveFrom(); - pause_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Pause").MoveFrom(); + notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification"); + pause_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Pause"); cmd_buff[3] = Kernel::g_handle_table.Create(notification_event).MoveFrom(); cmd_buff[4] = Kernel::g_handle_table.Create(pause_event).MoveFrom(); @@ -512,13 +512,13 @@ Interface::Interface() { file.ReadBytes(shared_font.data(), (size_t)file.GetSize()); // Create shared font memory object - shared_font_mem = Kernel::SharedMemory::Create("APT_U:shared_font_mem").MoveFrom(); + shared_font_mem = Kernel::SharedMemory::Create("APT_U:shared_font_mem"); } else { LOG_WARNING(Service_APT, "Unable to load shared font: %s", filepath.c_str()); shared_font_mem = nullptr; } - lock = Kernel::Mutex::Create(false, "APT_U:Lock").MoveFrom(); + lock = Kernel::Mutex::Create(false, "APT_U:Lock"); Register(FunctionTable); } diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 7a18c17477..0f86894a6f 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -201,8 +201,7 @@ const Interface::FunctionInfo FunctionTable[] = { // Interface class Interface::Interface() { - semaphore_event = Kernel::Event::Create(RESETTYPE_ONESHOT, - "DSP_DSP::semaphore_event").MoveFrom(); + semaphore_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "DSP_DSP::semaphore_event"); interrupt_event = nullptr; read_pipe_count = 0; diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp index 9362033186..495c117eee 100644 --- a/src/core/hle/service/gsp_gpu.cpp +++ b/src/core/hle/service/gsp_gpu.cpp @@ -187,7 +187,7 @@ static void RegisterInterruptRelayQueue(Service::Interface* self) { g_interrupt_event = Kernel::g_handle_table.Get(cmd_buff[3]); _assert_msg_(GSP, (g_interrupt_event != nullptr), "handle is not valid!"); - g_shared_memory = Kernel::SharedMemory::Create("GSPSharedMem").MoveFrom(); + g_shared_memory = Kernel::SharedMemory::Create("GSPSharedMem"); Handle shmem_handle = Kernel::g_handle_table.Create(g_shared_memory).MoveFrom(); diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index b6e4861d20..7cb01729e1 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -124,14 +124,14 @@ void PadUpdateComplete() { void HIDInit() { using namespace Kernel; - g_shared_mem = SharedMemory::Create("HID:SharedMem").MoveFrom(); + g_shared_mem = SharedMemory::Create("HID:SharedMem"); // Create event handles - g_event_pad_or_touch_1 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1").MoveFrom(); - g_event_pad_or_touch_2 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2").MoveFrom(); - g_event_accelerometer = Event::Create(RESETTYPE_ONESHOT, "HID:EventAccelerometer").MoveFrom(); - g_event_gyroscope = Event::Create(RESETTYPE_ONESHOT, "HID:EventGyroscope").MoveFrom(); - g_event_debug_pad = Event::Create(RESETTYPE_ONESHOT, "HID:EventDebugPad").MoveFrom(); + g_event_pad_or_touch_1 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1"); + g_event_pad_or_touch_2 = Event::Create(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2"); + g_event_accelerometer = Event::Create(RESETTYPE_ONESHOT, "HID:EventAccelerometer"); + g_event_gyroscope = Event::Create(RESETTYPE_ONESHOT, "HID:EventGyroscope"); + g_event_debug_pad = Event::Create(RESETTYPE_ONESHOT, "HID:EventDebugPad"); } void HIDShutdown() { diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index b140e9fe31..cc59a03ce2 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp @@ -23,7 +23,7 @@ static void GetProcSemaphore(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); // TODO(bunnei): Change to a semaphore once these have been implemented - event_handle = Kernel::Event::Create(RESETTYPE_ONESHOT, "SRV:Event").MoveFrom(); + event_handle = Kernel::Event::Create(RESETTYPE_ONESHOT, "SRV:Event"); event_handle->Clear(); cmd_buff[1] = 0; // No error diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 8bfa1428ea..34a27917fd 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -261,7 +261,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou static ResultCode CreateAddressArbiter(Handle* out_handle) { using Kernel::AddressArbiter; - CASCADE_RESULT(SharedPtr arbiter, AddressArbiter::Create()); + SharedPtr arbiter = AddressArbiter::Create(); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(arbiter))); LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *out_handle); return RESULT_SUCCESS; @@ -366,7 +366,7 @@ static ResultCode SetThreadPriority(Handle handle, s32 priority) { static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { using Kernel::Mutex; - CASCADE_RESULT(SharedPtr mutex, Mutex::Create(initial_locked != 0)); + SharedPtr mutex = Mutex::Create(initial_locked != 0); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", @@ -434,7 +434,9 @@ static ResultCode QueryMemory(void* info, void* out, u32 addr) { /// Create an event static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { - CASCADE_RESULT(auto evt, Kernel::Event::Create(static_cast(reset_type))); + using Kernel::Event; + + SharedPtr evt = Kernel::Event::Create(static_cast(reset_type)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", @@ -451,9 +453,10 @@ static ResultCode DuplicateHandle(Handle* out, Handle handle) { /// Signals an event static ResultCode SignalEvent(Handle handle) { + using Kernel::Event; LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); - auto evt = Kernel::g_handle_table.Get(handle); + SharedPtr evt = Kernel::g_handle_table.Get(handle); if (evt == nullptr) return ERR_INVALID_HANDLE; @@ -464,9 +467,10 @@ static ResultCode SignalEvent(Handle handle) { /// Clears an event static ResultCode ClearEvent(Handle handle) { + using Kernel::Event; LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); - auto evt = Kernel::g_handle_table.Get(handle); + SharedPtr evt = Kernel::g_handle_table.Get(handle); if (evt == nullptr) return ERR_INVALID_HANDLE; @@ -478,7 +482,7 @@ static ResultCode ClearEvent(Handle handle) { static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { using Kernel::Timer; - CASCADE_RESULT(auto timer, Timer::Create(static_cast(reset_type))); + SharedPtr timer = Timer::Create(static_cast(reset_type)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", @@ -552,7 +556,7 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 using Kernel::SharedMemory; // TODO(Subv): Implement this function - CASCADE_RESULT(auto shared_memory, SharedMemory::Create()); + SharedPtr shared_memory = SharedMemory::Create(); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);