Reworked the way thread_yield() works: just setting the thread to B_LOWEST_ACTIVE_PRIORITY
for one quantum wasn't really a good idea, as this could get quite expensive for the thread (depending on the system load, it might have taken a long time until the thread was scheduled again, no matter what priority it was). Also, calling thread_yield() in a loop would have taken 100% CPU time. Now, we sort the thread into the queue as with any other thread, but we'll ignore it once. This now guarantees an actual context switch, as well as a much fairer rescheduling policy for threads calling that function. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20077 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006, Axel Dörfler, [email protected].
|
||||
* Copyright 2002-2007, Axel Dörfler, [email protected].
|
||||
* Copyright 2002, Angelo Mottola, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
@@ -189,6 +189,13 @@ scheduler_reschedule(void)
|
||||
} else {
|
||||
// select next thread from the run queue
|
||||
while (nextThread && nextThread->priority > B_IDLE_PRIORITY) {
|
||||
if (oldThread == nextThread && nextThread->was_yielded) {
|
||||
// ignore threads that called thread_yield() once
|
||||
nextThread->was_yielded = false;
|
||||
prevThread = nextThread;
|
||||
nextThread = nextThread->queue_next;
|
||||
}
|
||||
|
||||
// always extract real time threads
|
||||
if (nextThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
|
||||
break;
|
||||
@@ -222,6 +229,7 @@ scheduler_reschedule(void)
|
||||
|
||||
nextThread->state = B_THREAD_RUNNING;
|
||||
nextThread->next_state = B_THREAD_READY;
|
||||
oldThread->was_yielded = false;
|
||||
|
||||
// track kernel time (user time is tracked in thread_at_kernel_entry())
|
||||
bigtime_t now = system_time();
|
||||
|
||||
Reference in New Issue
Block a user