diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f39c497d0..d96dd8eab 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -121,29 +121,24 @@ static bool CheckWaitType(const Thread* thread, WaitType type, Handle wait_handl } /// Stops the current thread -ResultCode StopThread(Handle handle, const char* reason) { - Thread* thread = g_handle_table.Get(handle); - if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel); - +void Thread::Stop(const char* reason) { // Release all the mutexes that this thread holds - ReleaseThreadMutexes(handle); + ReleaseThreadMutexes(GetHandle()); - ChangeReadyState(thread, false); - thread->status = THREADSTATUS_DORMANT; - for (Handle waiting_handle : thread->waiting_threads) { + ChangeReadyState(this, false); + status = THREADSTATUS_DORMANT; + for (Handle waiting_handle : waiting_threads) { Thread* waiting_thread = g_handle_table.Get(waiting_handle); - if (CheckWaitType(waiting_thread, WAITTYPE_THREADEND, handle)) + if (CheckWaitType(waiting_thread, WAITTYPE_THREADEND, GetHandle())) ResumeThreadFromWait(waiting_handle); } - thread->waiting_threads.clear(); + waiting_threads.clear(); // Stopped threads are never waiting. - thread->wait_type = WAITTYPE_NONE; - thread->wait_handle = 0; - thread->wait_address = 0; - - return RESULT_SUCCESS; + wait_type = WAITTYPE_NONE; + wait_handle = 0; + wait_address = 0; } /// Changes a threads state diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 27f85f53a..08481ab15 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -75,6 +75,8 @@ public: u32 GetThreadId() const { return thread_id; } + void Stop(const char* reason); + Core::ThreadContext context; u32 thread_id; @@ -107,9 +109,6 @@ Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZ /// Reschedules to the next available thread (call after current thread is suspended) void Reschedule(); -/// Stops the current thread -ResultCode StopThread(Handle thread, const char* reason); - /// Resumes a thread from waiting by marking it as "ready" void ResumeThreadFromWait(Handle handle); diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index a2a46ce6a..e607b5b8b 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -245,14 +245,11 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top } /// Called when a thread exits -static u32 ExitThread() { - Handle thread = Kernel::GetCurrentThread()->GetHandle(); +static void ExitThread() { + LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); - LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C - - Kernel::StopThread(thread, __func__); + Kernel::GetCurrentThread()->Stop(__func__); HLE::Reschedule(__func__); - return 0; } /// Gets the priority for the specified thread @@ -389,7 +386,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x06, nullptr, "GetProcessIdealProcessor"}, {0x07, nullptr, "SetProcessIdealProcessor"}, {0x08, HLE::Wrap, "CreateThread"}, - {0x09, HLE::Wrap, "ExitThread"}, + {0x09, ExitThread, "ExitThread"}, {0x0A, HLE::Wrap, "SleepThread"}, {0x0B, HLE::Wrap, "GetThreadPriority"}, {0x0C, HLE::Wrap, "SetThreadPriority"},