mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-24 00:30:10 +00:00
Thread: Move Get/SetThreadPriority to be Thread members
This commit is contained in:
parent
ff992edecf
commit
d1b7587647
@ -350,27 +350,8 @@ ResultVal<Handle> Thread::Create(const char* name, u32 entry_point, s32 priority
|
||||
return MakeResult<Handle>(*handle);
|
||||
}
|
||||
|
||||
/// Get the priority of the thread specified by handle
|
||||
ResultVal<u32> GetThreadPriority(const Handle handle) {
|
||||
Thread* thread = g_handle_table.Get<Thread>(handle);
|
||||
if (thread == nullptr) return InvalidHandle(ErrorModule::Kernel);
|
||||
|
||||
return MakeResult<u32>(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<Thread>(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
|
||||
|
@ -70,6 +70,9 @@ public:
|
||||
|
||||
ResultVal<bool> 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<u32> GetThreadPriority(const Handle handle);
|
||||
|
||||
/// Set the priority of the thread specified by handle
|
||||
ResultCode SetThreadPriority(Handle handle, s32 priority);
|
||||
|
||||
/// Initialize threading
|
||||
void ThreadingInit();
|
||||
|
||||
|
@ -256,16 +256,22 @@ static u32 ExitThread() {
|
||||
|
||||
/// Gets the priority for the specified thread
|
||||
static Result GetThreadPriority(s32* priority, Handle handle) {
|
||||
ResultVal<u32> 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<Kernel::Thread>(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<Kernel::Thread>(handle);
|
||||
if (thread == nullptr)
|
||||
return InvalidHandle(ErrorModule::Kernel).raw;
|
||||
|
||||
thread->SetPriority(priority);
|
||||
return RESULT_SUCCESS.raw;
|
||||
}
|
||||
|
||||
/// Create a mutex
|
||||
|
Loading…
Reference in New Issue
Block a user