Thread: Convert thread_queue to pointers
This commit is contained in:
parent
906da53958
commit
0b64705384
1 changed files with 10 additions and 14 deletions
|
@ -35,7 +35,7 @@ ResultVal<bool> Thread::WaitSynchronization() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lists all thread ids that aren't deleted/etc.
|
// Lists all thread ids that aren't deleted/etc.
|
||||||
static std::vector<Handle> thread_queue;
|
static std::vector<Thread*> thread_queue; // TODO(yuriks): Owned
|
||||||
|
|
||||||
// Lists only ready thread ids.
|
// Lists only ready thread ids.
|
||||||
static Common::ThreadQueueList<Handle> thread_ready_queue;
|
static Common::ThreadQueueList<Handle> thread_ready_queue;
|
||||||
|
@ -158,9 +158,7 @@ Handle ArbitrateHighestPriorityThread(Handle arbiter, u32 address) {
|
||||||
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 (Handle handle : thread_queue) {
|
for (Thread* thread : thread_queue) {
|
||||||
Thread* thread = g_handle_table.Get<Thread>(handle);
|
|
||||||
|
|
||||||
if (!CheckWaitType(thread, WAITTYPE_ARB, Kernel::g_handle_table.GetGeneric(arbiter), address))
|
if (!CheckWaitType(thread, WAITTYPE_ARB, Kernel::g_handle_table.GetGeneric(arbiter), address))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -168,7 +166,7 @@ Handle ArbitrateHighestPriorityThread(Handle arbiter, u32 address) {
|
||||||
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 = handle;
|
highest_priority_thread = thread->GetHandle();
|
||||||
priority = thread->current_priority;
|
priority = thread->current_priority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,9 +184,7 @@ Handle ArbitrateHighestPriorityThread(Handle arbiter, u32 address) {
|
||||||
void ArbitrateAllThreads(Handle arbiter, u32 address) {
|
void ArbitrateAllThreads(Handle 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 (Handle handle : thread_queue) {
|
for (Thread* thread : thread_queue) {
|
||||||
Thread* thread = g_handle_table.Get<Thread>(handle);
|
|
||||||
|
|
||||||
if (CheckWaitType(thread, WAITTYPE_ARB, Kernel::g_handle_table.GetGeneric(arbiter), address))
|
if (CheckWaitType(thread, WAITTYPE_ARB, Kernel::g_handle_table.GetGeneric(arbiter), address))
|
||||||
thread->ResumeFromWait();
|
thread->ResumeFromWait();
|
||||||
}
|
}
|
||||||
|
@ -272,10 +268,10 @@ void DebugThreadQueue() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThread()->GetHandle());
|
LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThread()->GetHandle());
|
||||||
for (Handle handle : thread_queue) {
|
for (Thread* t : thread_queue) {
|
||||||
s32 priority = thread_ready_queue.contains(handle);
|
s32 priority = thread_ready_queue.contains(t->GetHandle());
|
||||||
if (priority != -1) {
|
if (priority != -1) {
|
||||||
LOG_DEBUG(Kernel, "0x%02X 0x%08X", priority, handle);
|
LOG_DEBUG(Kernel, "0x%02X 0x%08X", priority, t->GetHandle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,12 +306,13 @@ ResultVal<Thread*> Thread::Create(const char* name, u32 entry_point, s32 priorit
|
||||||
Thread* thread = new Thread;
|
Thread* thread = new Thread;
|
||||||
|
|
||||||
// TODO(yuriks): Thread requires a handle to be inserted into the various scheduling queues for now.
|
// TODO(yuriks): Thread requires a handle to be inserted into the various scheduling queues for now.
|
||||||
|
// TODO(yuriks): Don't create handle
|
||||||
ResultVal<Handle> handle = Kernel::g_handle_table.Create(thread);
|
ResultVal<Handle> handle = Kernel::g_handle_table.Create(thread);
|
||||||
// TODO(yuriks): Plug memory leak
|
// TODO(yuriks): Plug memory leak
|
||||||
if (handle.Failed())
|
if (handle.Failed())
|
||||||
return handle.Code();
|
return handle.Code();
|
||||||
|
|
||||||
thread_queue.push_back(*handle);
|
thread_queue.push_back(thread);
|
||||||
thread_ready_queue.prepare(priority);
|
thread_ready_queue.prepare(priority);
|
||||||
|
|
||||||
thread->thread_id = next_thread_id++;
|
thread->thread_id = next_thread_id++;
|
||||||
|
@ -398,8 +395,7 @@ void Reschedule() {
|
||||||
} else {
|
} else {
|
||||||
LOG_TRACE(Kernel, "cannot context switch from 0x%08X, no higher priority thread!", prev->GetHandle());
|
LOG_TRACE(Kernel, "cannot context switch from 0x%08X, no higher priority thread!", prev->GetHandle());
|
||||||
|
|
||||||
for (Handle handle : thread_queue) {
|
for (Thread* thread : thread_queue) {
|
||||||
Thread* thread = g_handle_table.Get<Thread>(handle);
|
|
||||||
LOG_TRACE(Kernel, "\thandle=0x%08X prio=0x%02X, status=0x%08X wait_type=0x%08X wait_handle=0x%08X",
|
LOG_TRACE(Kernel, "\thandle=0x%08X prio=0x%02X, status=0x%08X wait_type=0x%08X wait_handle=0x%08X",
|
||||||
thread->GetHandle(), thread->current_priority, thread->status, thread->wait_type, thread->wait_object->GetHandle());
|
thread->GetHandle(), thread->current_priority, thread->status, thread->wait_type, thread->wait_object->GetHandle());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue