Update sema_up to yield CPU if unblocked has higher priority
This commit is contained in:
@@ -114,11 +114,22 @@ sema_up (struct semaphore *sema)
|
||||
ASSERT (sema != NULL);
|
||||
|
||||
old_level = intr_disable ();
|
||||
if (!list_empty (&sema->waiters))
|
||||
thread_unblock (list_entry (list_pop_front (&sema->waiters),
|
||||
struct thread, elem));
|
||||
|
||||
/* Wake up (unblock) the highest priority thread from the waiters list */
|
||||
struct thread *t = NULL;
|
||||
if (!list_empty (&sema->waiters))
|
||||
{
|
||||
t = list_entry (list_pop_front (&sema->waiters), struct thread, elem);
|
||||
thread_unblock (t);
|
||||
}
|
||||
|
||||
sema->value++;
|
||||
intr_set_level (old_level);
|
||||
|
||||
/* If the unblocked thread has higher priority than the current running thread
|
||||
then yield the CPU to the unblocked thread */
|
||||
if (!intr_context() && t != NULL && t->priority > thread_get_priority ())
|
||||
thread_yield ();
|
||||
}
|
||||
|
||||
static void sema_test_helper (void *sema_);
|
||||
|
||||
Reference in New Issue
Block a user