Merge 'task1/priority-donation' into 'master' #14

Merged
sb3923 merged 66 commits from task1/priority-donation into master 2024-10-23 16:15:45 +00:00
4 changed files with 83 additions and 6 deletions
Showing only changes of commit 0d6fb2f167 - Show all commits

View File

@@ -114,11 +114,22 @@ sema_up (struct semaphore *sema)
ASSERT (sema != NULL);
old_level = intr_disable ();
/* Wake up (unblock) the highest priority thread from the waiters list */
struct thread *t = NULL;
if (!list_empty (&sema->waiters))
thread_unblock (list_entry (list_pop_front (&sema->waiters),
struct thread, elem));
{
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_);