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);
|
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
|
/// Set the priority of the thread specified by handle
|
||||||
ResultCode SetThreadPriority(Handle handle, s32 priority) {
|
void Thread::SetPriority(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!");
|
|
||||||
|
|
||||||
// If priority is invalid, clamp to valid range
|
// If priority is invalid, clamp to valid range
|
||||||
if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
|
if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) {
|
||||||
s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
|
s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST);
|
||||||
@ -381,20 +362,18 @@ ResultCode SetThreadPriority(Handle handle, s32 priority) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Change thread priority
|
// Change thread priority
|
||||||
s32 old = thread->current_priority;
|
s32 old = current_priority;
|
||||||
thread_ready_queue.remove(old, handle);
|
thread_ready_queue.remove(old, GetHandle());
|
||||||
thread->current_priority = priority;
|
current_priority = priority;
|
||||||
thread_ready_queue.prepare(thread->current_priority);
|
thread_ready_queue.prepare(current_priority);
|
||||||
|
|
||||||
// Change thread status to "ready" and push to ready queue
|
// Change thread status to "ready" and push to ready queue
|
||||||
if (thread->IsRunning()) {
|
if (IsRunning()) {
|
||||||
thread->status = (thread->status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY;
|
status = (status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY;
|
||||||
}
|
}
|
||||||
if (thread->IsReady()) {
|
if (IsReady()) {
|
||||||
thread_ready_queue.push_back(thread->current_priority, handle);
|
thread_ready_queue.push_back(current_priority, GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets up the primary application thread
|
/// Sets up the primary application thread
|
||||||
|
@ -70,6 +70,9 @@ public:
|
|||||||
|
|
||||||
ResultVal<bool> WaitSynchronization() override;
|
ResultVal<bool> WaitSynchronization() override;
|
||||||
|
|
||||||
|
s32 GetPriority() const { return current_priority; }
|
||||||
|
void SetPriority(s32 priority);
|
||||||
|
|
||||||
Core::ThreadContext context;
|
Core::ThreadContext context;
|
||||||
|
|
||||||
u32 thread_id;
|
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
|
/// Put current thread in a wait state - on WaitSynchronization
|
||||||
void WaitThread_Synchronization();
|
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
|
/// Initialize threading
|
||||||
void ThreadingInit();
|
void ThreadingInit();
|
||||||
|
|
||||||
|
@ -256,16 +256,22 @@ static u32 ExitThread() {
|
|||||||
|
|
||||||
/// Gets the priority for the specified thread
|
/// Gets the priority for the specified thread
|
||||||
static Result GetThreadPriority(s32* priority, Handle handle) {
|
static Result GetThreadPriority(s32* priority, Handle handle) {
|
||||||
ResultVal<u32> priority_result = Kernel::GetThreadPriority(handle);
|
const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
|
||||||
if (priority_result.Succeeded()) {
|
if (thread == nullptr)
|
||||||
*priority = *priority_result;
|
return InvalidHandle(ErrorModule::Kernel).raw;
|
||||||
}
|
|
||||||
return priority_result.Code().raw;
|
*priority = thread->GetPriority();
|
||||||
|
return RESULT_SUCCESS.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the priority for the specified thread
|
/// Sets the priority for the specified thread
|
||||||
static Result SetThreadPriority(Handle handle, s32 priority) {
|
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
|
/// Create a mutex
|
||||||
|
Loading…
Reference in New Issue
Block a user