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