kernel: Move thread retrieving code to separate function
This commit is contained in:
parent
03e3a82953
commit
94f4574d78
@ -346,6 +346,35 @@ static inline bigtime_t simple_compute_quantum(Thread* thread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline Thread*
|
||||||
|
simple_get_next_thread(void)
|
||||||
|
{
|
||||||
|
Thread* thread;
|
||||||
|
do {
|
||||||
|
thread = sRunQueue->PeekMaximum();
|
||||||
|
|
||||||
|
if (sYieldedThreadPriority >= 0 && thread != NULL
|
||||||
|
&& thread_is_idle_thread(thread)) {
|
||||||
|
sRunQueue->Remove(thread);
|
||||||
|
simple_enqueue_in_run_queue(thread);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
} while (true);
|
||||||
|
if (thread == NULL && sYieldedThreadPriority >= 0) {
|
||||||
|
SimpleRunQueue* temp = sRunQueue;
|
||||||
|
sRunQueue = sExpiredQueue;
|
||||||
|
sExpiredQueue = temp;
|
||||||
|
sYieldedThreadPriority = -1;
|
||||||
|
|
||||||
|
thread = sRunQueue->PeekMaximum();
|
||||||
|
}
|
||||||
|
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Runs the scheduler.
|
/*! Runs the scheduler.
|
||||||
Note: expects thread spinlock to be held
|
Note: expects thread spinlock to be held
|
||||||
*/
|
*/
|
||||||
@ -353,7 +382,6 @@ static void
|
|||||||
simple_reschedule(void)
|
simple_reschedule(void)
|
||||||
{
|
{
|
||||||
Thread* oldThread = thread_get_current_thread();
|
Thread* oldThread = thread_get_current_thread();
|
||||||
Thread* nextThread;
|
|
||||||
|
|
||||||
// check whether we're only supposed to reschedule, if the current thread
|
// check whether we're only supposed to reschedule, if the current thread
|
||||||
// is idle
|
// is idle
|
||||||
@ -417,29 +445,9 @@ simple_reschedule(void)
|
|||||||
schedulerOldThreadData->lost_cpu = false;
|
schedulerOldThreadData->lost_cpu = false;
|
||||||
|
|
||||||
// select thread with the biggest priority
|
// select thread with the biggest priority
|
||||||
do {
|
Thread* nextThread = simple_get_next_thread();
|
||||||
nextThread = sRunQueue->PeekMaximum();
|
|
||||||
|
|
||||||
if (sYieldedThreadPriority >= 0 && nextThread != NULL
|
|
||||||
&& thread_is_idle_thread(nextThread)) {
|
|
||||||
sRunQueue->Remove(nextThread);
|
|
||||||
simple_enqueue_in_run_queue(nextThread);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
} while (true);
|
|
||||||
if (nextThread == NULL && sYieldedThreadPriority >= 0) {
|
|
||||||
RunQueue<Thread, THREAD_MAX_SET_PRIORITY>* temp = sRunQueue;
|
|
||||||
sRunQueue = sExpiredQueue;
|
|
||||||
sExpiredQueue = temp;
|
|
||||||
sYieldedThreadPriority = -1;
|
|
||||||
|
|
||||||
nextThread = sRunQueue->PeekMaximum();
|
|
||||||
}
|
|
||||||
if (!nextThread)
|
if (!nextThread)
|
||||||
panic("reschedule(): run queue is empty!\n");
|
panic("reschedule(): run queues are empty!\n");
|
||||||
|
|
||||||
sRunQueue->Remove(nextThread);
|
sRunQueue->Remove(nextThread);
|
||||||
|
|
||||||
T(ScheduleThread(nextThread, oldThread));
|
T(ScheduleThread(nextThread, oldThread));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user