Thread: Convert thread_ready_queue to pointers

This commit is contained in:
Yuri Kunde Schlesner 2014-12-22 13:00:11 -02:00
parent 0b64705384
commit 5619e790b8

View file

@ -38,7 +38,7 @@ ResultVal<bool> Thread::WaitSynchronization() {
static std::vector<Thread*> thread_queue; // TODO(yuriks): Owned
// Lists only ready thread ids.
static Common::ThreadQueueList<Handle> thread_ready_queue;
static Common::ThreadQueueList<Thread*> thread_ready_queue;
static Thread* current_thread;
@ -88,16 +88,15 @@ void ResetThread(Thread* t, u32 arg, s32 lowest_priority) {
/// Change a thread to "ready" state
void ChangeReadyState(Thread* t, bool ready) {
Handle handle = t->GetHandle();
if (t->IsReady()) {
if (!ready) {
thread_ready_queue.remove(t->current_priority, handle);
thread_ready_queue.remove(t->current_priority, t);
}
} else if (ready) {
if (t->IsRunning()) {
thread_ready_queue.push_front(t->current_priority, handle);
thread_ready_queue.push_front(t->current_priority, t);
} else {
thread_ready_queue.push_back(t->current_priority, handle);
thread_ready_queue.push_back(t->current_priority, t);
}
t->status = THREADSTATUS_READY;
}
@ -225,7 +224,7 @@ void SwitchContext(Thread* t) {
/// Gets the next thread that is ready to be run by priority
Thread* NextThread() {
Handle next;
Thread* next;
Thread* cur = GetCurrentThread();
if (cur && cur->IsRunning()) {
@ -236,7 +235,7 @@ Thread* NextThread() {
if (next == 0) {
return nullptr;
}
return Kernel::g_handle_table.Get<Thread>(next);
return next;
}
void WaitCurrentThread(WaitType wait_type, Object* wait_object) {
@ -269,7 +268,7 @@ void DebugThreadQueue() {
}
LOG_DEBUG(Kernel, "0x%02X 0x%08X (current)", thread->current_priority, GetCurrentThread()->GetHandle());
for (Thread* t : thread_queue) {
s32 priority = thread_ready_queue.contains(t->GetHandle());
s32 priority = thread_ready_queue.contains(t);
if (priority != -1) {
LOG_DEBUG(Kernel, "0x%02X 0x%08X", priority, t->GetHandle());
}
@ -346,7 +345,7 @@ void Thread::SetPriority(s32 priority) {
// Change thread priority
s32 old = current_priority;
thread_ready_queue.remove(old, GetHandle());
thread_ready_queue.remove(old, this);
current_priority = priority;
thread_ready_queue.prepare(current_priority);
@ -355,7 +354,7 @@ void Thread::SetPriority(s32 priority) {
status = (status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY;
}
if (IsReady()) {
thread_ready_queue.push_back(current_priority, GetHandle());
thread_ready_queue.push_back(current_priority, this);
}
}