- for(thread = gaActiveThreads[i]; thread; thread = thread->Next)
- {
- if( thread->CurCPU == -1 ) break;
- }
- // If we fall onto the same queue again, special handling is
- // needed
- if( Last && Last->Status == THREAD_STAT_ACTIVE && i == Last->Priority ) {
- tThread *savedThread = thread;
-
- // Find the next unscheduled thread in the list
- for( thread = Last->Next; thread; thread = thread->Next )
- {
- if( thread->CurCPU == -1 ) break;
- }
- // If we don't find anything after, just use the one
- // found above.
- if( !thread ) thread = savedThread;
- }
- // Found a thread? Schedule it!
- if( thread ) break;
+ if( !gaActiveThreads[i].Head )
+ continue ;
+
+ thread = gaActiveThreads[i].Head;
+
+ // Remove from head
+ gaActiveThreads[i].Head = thread->Next;
+ if(!thread->Next)
+ gaActiveThreads[i].Tail = NULL;
+ thread->Next = NULL;
+ break;