From 47af34003b97a27ee8456cedb367b41f8687b517 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 5 Mar 2021 00:13:29 -0800 Subject: hle: kernel: KThread: Rework dummy threads & fix memory leak. - Dummy threads are created on thread local storage for all host threads. - Fixes a leak by removing creation of fibers, which are not applicable here. --- src/core/hle/kernel/k_thread.cpp | 50 +++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'src/core/hle/kernel/k_thread.cpp') diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 1661afbd9..e0f53287c 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp @@ -995,22 +995,11 @@ std::shared_ptr& KThread::GetHostContext() { return host_context; } -ResultVal> KThread::Create(Core::System& system, ThreadType type_flags, - std::string name, VAddr entry_point, - u32 priority, u64 arg, s32 processor_id, - VAddr stack_top, Process* owner_process) { - std::function init_func = Core::CpuManager::GetGuestThreadStartFunc(); - void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); - return Create(system, type_flags, name, entry_point, priority, arg, processor_id, stack_top, - owner_process, std::move(init_func), init_func_parameter); -} - -ResultVal> KThread::Create(Core::System& system, ThreadType type_flags, - std::string name, VAddr entry_point, - u32 priority, u64 arg, s32 processor_id, - VAddr stack_top, Process* owner_process, - std::function&& thread_start_func, - void* thread_start_parameter) { +ResultVal> KThread::CreateThread(Core::System& system, + ThreadType type_flags, std::string name, + VAddr entry_point, u32 priority, u64 arg, + s32 processor_id, VAddr stack_top, + Process* owner_process) { auto& kernel = system.Kernel(); std::shared_ptr thread = std::make_shared(kernel); @@ -1027,12 +1016,35 @@ ResultVal> KThread::Create(Core::System& system, Thread auto& scheduler = kernel.GlobalSchedulerContext(); scheduler.AddThread(thread); - thread->host_context = - std::make_shared(std::move(thread_start_func), thread_start_parameter); - return MakeResult>(std::move(thread)); } +ResultVal> KThread::CreateThread( + Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point, u32 priority, + u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process, + std::function&& thread_start_func, void* thread_start_parameter) { + auto thread_result = CreateThread(system, type_flags, name, entry_point, priority, arg, + processor_id, stack_top, owner_process); + + if (thread_result.Succeeded()) { + (*thread_result)->host_context = + std::make_shared(std::move(thread_start_func), thread_start_parameter); + } + + return thread_result; +} + +ResultVal> KThread::CreateUserThread( + Core::System& system, ThreadType type_flags, std::string name, VAddr entry_point, u32 priority, + u64 arg, s32 processor_id, VAddr stack_top, Process* owner_process) { + std::function init_func = Core::CpuManager::GetGuestThreadStartFunc(); + + void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); + + return CreateThread(system, type_flags, name, entry_point, priority, arg, processor_id, + stack_top, owner_process, std::move(init_func), init_func_parameter); +} + KThread* GetCurrentThreadPointer(KernelCore& kernel) { return kernel.GetCurrentEmuThread(); } -- cgit v1.2.3