diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f0c5e394a..f3c48e824 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -350,27 +350,8 @@ ResultVal Thread::Create(const char* name, u32 entry_point, s32 priority return MakeResult(*handle); } -/// Get the priority of the thread specified by handle -ResultVal GetThreadPriority(const Handle handle) { - Thread* thread = g_handle_table.Get(handle); - if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel); - - return MakeResult(thread->current_priority); -} - /// Set the priority of the thread specified by handle -ResultCode SetThreadPriority(Handle handle, s32 priority) { - Thread* thread = nullptr; - if (!handle) { - thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior? - } else { - thread = g_handle_table.Get(handle); - if (thread == nullptr) { - return InvalidHandle(ErrorModule::Kernel); - } - } - _assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!"); - +void Thread::SetPriority(s32 priority) { // If priority is invalid, clamp to valid range if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); @@ -381,20 +362,18 @@ ResultCode SetThreadPriority(Handle handle, s32 priority) { } // Change thread priority - s32 old = thread->current_priority; - thread_ready_queue.remove(old, handle); - thread->current_priority = priority; - thread_ready_queue.prepare(thread->current_priority); + s32 old = current_priority; + thread_ready_queue.remove(old, GetHandle()); + current_priority = priority; + thread_ready_queue.prepare(current_priority); // Change thread status to "ready" and push to ready queue - if (thread->IsRunning()) { - thread->status = (thread->status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY; + if (IsRunning()) { + status = (status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY; } - if (thread->IsReady()) { - thread_ready_queue.push_back(thread->current_priority, handle); + if (IsReady()) { + thread_ready_queue.push_back(current_priority, GetHandle()); } - - return RESULT_SUCCESS; } /// Sets up the primary application thread diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 542dbdab5..c407301b8 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -70,6 +70,9 @@ public: ResultVal WaitSynchronization() override; + s32 GetPriority() const { return current_priority; } + void SetPriority(s32 priority); + Core::ThreadContext context; u32 thread_id; @@ -146,12 +149,6 @@ void WaitCurrentThread(WaitType wait_type, Handle wait_handle, VAddr wait_addres /// Put current thread in a wait state - on WaitSynchronization void WaitThread_Synchronization(); -/// Get the priority of the thread specified by handle -ResultVal GetThreadPriority(const Handle handle); - -/// Set the priority of the thread specified by handle -ResultCode SetThreadPriority(Handle handle, s32 priority); - /// Initialize threading void ThreadingInit(); diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 72976f655..32d20116d 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -256,16 +256,22 @@ static u32 ExitThread() { /// Gets the priority for the specified thread static Result GetThreadPriority(s32* priority, Handle handle) { - ResultVal priority_result = Kernel::GetThreadPriority(handle); - if (priority_result.Succeeded()) { - *priority = *priority_result; - } - return priority_result.Code().raw; + const Kernel::Thread* thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + *priority = thread->GetPriority(); + return RESULT_SUCCESS.raw; } /// Sets the priority for the specified thread static Result SetThreadPriority(Handle handle, s32 priority) { - return Kernel::SetThreadPriority(handle, priority).raw; + Kernel::Thread* thread = Kernel::g_handle_table.Get(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + thread->SetPriority(priority); + return RESULT_SUCCESS.raw; } /// Create a mutex