Thread: Remove the last Handle-based interfaces from Thread.cpp

This commit is contained in:
Yuri Kunde Schlesner 2014-12-22 13:00:58 -02:00
parent 5619e790b8
commit c91d2e959b
3 changed files with 13 additions and 14 deletions

View File

@ -40,11 +40,11 @@ ResultCode ArbitrateAddress(Handle handle, ArbitrationType type, u32 address, s3
case ArbitrationType::Signal: case ArbitrationType::Signal:
// Negative value means resume all threads // Negative value means resume all threads
if (value < 0) { if (value < 0) {
ArbitrateAllThreads(handle, address); ArbitrateAllThreads(object, address);
} else { } else {
// Resume first N threads // Resume first N threads
for(int i = 0; i < value; i++) for(int i = 0; i < value; i++)
ArbitrateHighestPriorityThread(handle, address); ArbitrateHighestPriorityThread(object, address);
} }
break; break;

View File

@ -152,39 +152,38 @@ void ChangeThreadState(Thread* t, ThreadStatus new_status) {
} }
/// Arbitrate the highest priority thread that is waiting /// Arbitrate the highest priority thread that is waiting
Handle ArbitrateHighestPriorityThread(Handle arbiter, u32 address) { Thread* ArbitrateHighestPriorityThread(Object* arbiter, u32 address) {
Handle highest_priority_thread = 0; Thread* highest_priority_thread = nullptr;
s32 priority = THREADPRIO_LOWEST; s32 priority = THREADPRIO_LOWEST;
// Iterate through threads, find highest priority thread that is waiting to be arbitrated... // Iterate through threads, find highest priority thread that is waiting to be arbitrated...
for (Thread* thread : thread_queue) { for (Thread* thread : thread_queue) {
if (!CheckWaitType(thread, WAITTYPE_ARB, Kernel::g_handle_table.GetGeneric(arbiter), address)) if (!CheckWaitType(thread, WAITTYPE_ARB, arbiter, address))
continue; continue;
if (thread == nullptr) if (thread == nullptr)
continue; // TODO(yuriks): Thread handle will hang around forever. Should clean up. continue; // TODO(yuriks): Thread handle will hang around forever. Should clean up.
if(thread->current_priority <= priority) { if(thread->current_priority <= priority) {
highest_priority_thread = thread->GetHandle(); highest_priority_thread = thread;
priority = thread->current_priority; priority = thread->current_priority;
} }
} }
// If a thread was arbitrated, resume it // If a thread was arbitrated, resume it
if (0 != highest_priority_thread) { if (nullptr != highest_priority_thread) {
Thread* thread = Kernel::g_handle_table.Get<Thread>(highest_priority_thread); highest_priority_thread->ResumeFromWait();
if (thread != nullptr)
thread->ResumeFromWait();
} }
return highest_priority_thread; return highest_priority_thread;
} }
/// Arbitrate all threads currently waiting /// Arbitrate all threads currently waiting
void ArbitrateAllThreads(Handle arbiter, u32 address) { void ArbitrateAllThreads(Object* arbiter, u32 address) {
// Iterate through threads, find highest priority thread that is waiting to be arbitrated... // Iterate through threads, find highest priority thread that is waiting to be arbitrated...
for (Thread* thread : thread_queue) { for (Thread* thread : thread_queue) {
if (CheckWaitType(thread, WAITTYPE_ARB, Kernel::g_handle_table.GetGeneric(arbiter), address)) if (CheckWaitType(thread, WAITTYPE_ARB, arbiter, address))
thread->ResumeFromWait(); thread->ResumeFromWait();
} }
} }

View File

@ -112,10 +112,10 @@ Thread* SetupMainThread(s32 priority, int stack_size = Kernel::DEFAULT_STACK_SIZ
void Reschedule(); void Reschedule();
/// Arbitrate the highest priority thread that is waiting /// Arbitrate the highest priority thread that is waiting
Handle ArbitrateHighestPriorityThread(Handle arbiter, u32 address); Thread* ArbitrateHighestPriorityThread(Object* arbiter, u32 address);
/// Arbitrate all threads currently waiting... /// Arbitrate all threads currently waiting...
void ArbitrateAllThreads(Handle arbiter, u32 address); void ArbitrateAllThreads(Object* arbiter, u32 address);
/// Gets the current thread /// Gets the current thread
Thread* GetCurrentThread(); Thread* GetCurrentThread();