diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index e43c3ee4e..cecc2fb58 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -33,7 +33,7 @@ public: ResultVal WaitSynchronization() override { bool wait = locked; if (locked) { - Handle thread = GetCurrentThreadHandle(); + Handle thread = GetCurrentThread()->GetHandle(); if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) { waiting_threads.push_back(thread); } diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 558068c79..d3468c19c 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -40,7 +40,7 @@ static MutexMap g_mutex_held_locks; * @param mutex Mutex that is to be acquired * @param thread Thread that will acquired */ -void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThreadHandle()) { +void MutexAcquireLock(Mutex* mutex, Handle thread = GetCurrentThread()->GetHandle()) { g_mutex_held_locks.insert(std::make_pair(thread, mutex->GetHandle())); mutex->lock_thread = thread; } diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp index 6bc8066a6..fbf6de0e7 100644 --- a/src/core/hle/kernel/semaphore.cpp +++ b/src/core/hle/kernel/semaphore.cpp @@ -38,7 +38,7 @@ public: if (wait) { Kernel::WaitCurrentThread(WAITTYPE_SEMA, GetHandle()); - waiting_threads.push(GetCurrentThreadHandle()); + waiting_threads.push(GetCurrentThread()->GetHandle()); } else { --available_count; } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f3c48e824..7a235a64b 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -24,7 +24,7 @@ namespace Kernel { ResultVal Thread::WaitSynchronization() { const bool wait = status != THREADSTATUS_DORMANT; if (wait) { - Handle thread = GetCurrentThreadHandle(); + Handle thread = GetCurrentThread()->GetHandle(); if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) { waiting_threads.push_back(thread); } @@ -50,11 +50,6 @@ Thread* GetCurrentThread() { return current_thread; } -/// Gets the current thread handle -Handle GetCurrentThreadHandle() { - return GetCurrentThread()->GetHandle(); -} - /// Sets the current thread inline void SetCurrentThread(Thread* t) { current_thread = t; @@ -285,7 +280,7 @@ void DebugThreadQueue() { if (!thread) { return; } - LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThreadHandle()); + LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThread()->GetHandle()); for (u32 i = 0; i < thread_queue.size(); i++) { Handle handle = thread_queue[i]; s32 priority = thread_ready_queue.contains(handle); @@ -429,17 +424,6 @@ void Reschedule() { ResumeThreadFromWait(prev->GetHandle()); } -ResultCode GetThreadId(u32* thread_id, Handle handle) { - Thread* thread = g_handle_table.Get(handle); - if (thread == nullptr) - return ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS, - ErrorSummary::WrongArgument, ErrorLevel::Permanent); - - *thread_id = thread->thread_id; - - return RESULT_SUCCESS; -} - //////////////////////////////////////////////////////////////////////////////////////////////////// void ThreadingInit() { diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index c407301b8..3fdb27965 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -73,6 +73,8 @@ public: s32 GetPriority() const { return current_priority; } void SetPriority(s32 priority); + u32 GetThreadId() const { return thread_id; } + Core::ThreadContext context; u32 thread_id; @@ -108,14 +110,6 @@ void Reschedule(); /// Stops the current thread ResultCode StopThread(Handle thread, const char* reason); -/** - * Retrieves the ID of the specified thread handle - * @param thread_id Will contain the output thread id - * @param handle Handle to the thread we want - * @return Whether the function was successful or not - */ -ResultCode GetThreadId(u32* thread_id, Handle handle); - /// Resumes a thread from waiting by marking it as "ready" void ResumeThreadFromWait(Handle handle); @@ -128,15 +122,12 @@ void ArbitrateAllThreads(u32 arbiter, u32 address); /// Gets the current thread Thread* GetCurrentThread(); -/// Gets the current thread handle -Handle GetCurrentThreadHandle(); - /** * Puts the current thread in the wait state for the given type * @param wait_type Type of wait * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread */ -void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle()); +void WaitCurrentThread(WaitType wait_type, Handle wait_handle = GetCurrentThread()->GetHandle()); /** * Puts the current thread in the wait state for the given type diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 32d20116d..760bcb878 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -245,7 +245,7 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top /// Called when a thread exits static u32 ExitThread() { - Handle thread = Kernel::GetCurrentThreadHandle(); + Handle thread = Kernel::GetCurrentThread()->GetHandle(); LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C @@ -292,8 +292,13 @@ static Result ReleaseMutex(Handle handle) { /// Get the ID for the specified thread. static Result GetThreadId(u32* thread_id, Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); - ResultCode result = Kernel::GetThreadId(thread_id, handle); - return result.raw; + + const Kernel::Thread* thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + *thread_id = thread->GetThreadId(); + return RESULT_SUCCESS.raw; } /// Creates a semaphore