diff options
author | bunnei <ericbunnie@gmail.com> | 2014-06-02 04:12:54 +0200 |
---|---|---|
committer | bunnei <ericbunnie@gmail.com> | 2014-06-02 04:12:54 +0200 |
commit | 3fb31fbc57fd1d537db79af898ef26c92b0e0867 (patch) | |
tree | a4ce54e66ae91c66c0ce55ab32468b3b8ec4d6ab /src/core/hle/kernel | |
parent | kernel: changed main thread priority to default, updated Kernel::Reschedule to use PrepareReschedule (diff) | |
download | yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.gz yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.bz2 yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.lz yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.xz yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.zst yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.zip |
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r-- | src/core/hle/kernel/thread.cpp | 45 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.h | 6 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f2094f7a7..c84fdf91d 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -294,6 +294,51 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3 return handle; } +/// Get the priority of the thread specified by handle +u32 GetThreadPriority(const Handle handle) { + Thread* thread = g_object_pool.GetFast<Thread>(handle); + _assert_msg_(KERNEL, thread, "called, but thread is NULL!"); + return thread->current_priority; +} + +/// Set the priority of the thread specified by handle +Result SetThreadPriority(Handle handle, s32 priority) { + Thread* thread = NULL; + if (!handle) { + thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior? + } else { + thread = g_object_pool.GetFast<Thread>(handle); + } + _assert_msg_(KERNEL, thread, "called, but thread is NULL!"); + + // If priority is invalid, clamp to valid range + if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { + s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); + WARN_LOG(KERNEL, "invalid priority=0x%08X, clamping to %08X", priority, new_priority); + // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm + // validity of this + priority = new_priority; + } + + // Change thread priority + s32 old = thread->current_priority; + g_thread_ready_queue.remove(old, handle); + thread->current_priority = priority; + g_thread_ready_queue.prepare(thread->current_priority); + + // Change thread status to "ready" and push to ready queue + if (thread->IsRunning()) { + thread->status = (thread->status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY; + } + if (thread->IsReady()) { + g_thread_ready_queue.push_back(thread->current_priority, handle); + } + + HLE::EatCycles(450); + + return 0; +} + /// Sets up the primary application thread Handle SetupMainThread(s32 priority, int stack_size) { Handle handle; diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 9628f165d..094c8d43e 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -65,6 +65,12 @@ Handle GetCurrentThreadHandle(); /// Put current thread in a wait state - on WaitSynchronization void WaitThread_Synchronization(); +/// Get the priority of the thread specified by handle +u32 GetThreadPriority(const Handle handle); + +/// Set the priority of the thread specified by handle +Result SetThreadPriority(Handle handle, s32 priority); + /// Initialize threading void ThreadingInit(); |