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 245 additions and 16 deletions
Showing only changes of commit 78c6fd36e3 - Show all commits

View File

@@ -115,6 +115,8 @@ sema_up (struct semaphore *sema)
old_level = intr_disable (); old_level = intr_disable ();
if (!list_empty (&sema->waiters)) if (!list_empty (&sema->waiters))
{ {
/* Enforces wake-up of the highest priority thread waiting for the
semaphore. */
struct list_elem *e = list_min (&sema->waiters, priority_more, NULL); struct list_elem *e = list_min (&sema->waiters, priority_more, NULL);
list_remove (e); list_remove (e);
thread_unblock (list_entry (e, struct thread, elem)); thread_unblock (list_entry (e, struct thread, elem));
@@ -122,6 +124,9 @@ sema_up (struct semaphore *sema)
sema->value++; sema->value++;
intr_set_level (old_level); intr_set_level (old_level);
/* Yields the CPU in case the thread that has been woken up has a higher
priority that the current running thread, including the case when called
within an interrupt handler. */
if (intr_context ()) if (intr_context ())
intr_yield_on_return (); intr_yield_on_return ();
else else