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:
@@ -214,6 +214,7 @@ create_thread_struct(const char *name, thread_id threadID)
|
||||
thread->sig_block_mask = 0;
|
||||
memset(thread->sig_action, 0, 32 * sizeof(struct sigaction));
|
||||
thread->in_kernel = true;
|
||||
thread->was_yielded = false;
|
||||
thread->user_time = 0;
|
||||
thread->kernel_time = 0;
|
||||
thread->last_time = 0;
|
||||
@@ -915,13 +916,13 @@ thread_exit(void)
|
||||
struct thread_debug_info debugInfo;
|
||||
team_id teamID = team->id;
|
||||
|
||||
if (!are_interrupts_enabled())
|
||||
dprintf("thread_exit() called with interrupts disabled!\n");
|
||||
|
||||
TRACE(("thread 0x%lx exiting %s w/return code 0x%x\n", thread->id,
|
||||
thread->exit.reason == THREAD_RETURN_INTERRUPTED ? "due to signal" : "normally",
|
||||
(int)thread->exit.status));
|
||||
|
||||
if (!are_interrupts_enabled())
|
||||
panic("thread_exit() called with interrupts disabled!\n");
|
||||
|
||||
// boost our priority to get this over with
|
||||
thread->priority = thread->next_priority = B_URGENT_DISPLAY_PRIORITY;
|
||||
|
||||
@@ -1298,8 +1299,8 @@ thread_yield(void)
|
||||
state = disable_interrupts();
|
||||
GRAB_THREAD_LOCK();
|
||||
|
||||
// just add the thread at the end of the run queue
|
||||
thread->next_priority = B_LOWEST_ACTIVE_PRIORITY;
|
||||
// mark the thread as yielded, so it will not be scheduled next
|
||||
thread->was_yielded = true;
|
||||
scheduler_reschedule();
|
||||
|
||||
RELEASE_THREAD_LOCK();
|
||||
|
||||
Reference in New Issue
Block a user