Update semaphore priority scheduling to use linear search on unordered list w/ S

This commit is contained in:
Themis Demetriades
2024-10-20 22:50:31 +01:00
parent 840df8af78
commit dae5b0d097

View File

@@ -68,8 +68,7 @@ sema_down (struct semaphore *sema)
old_level = intr_disable ();
while (sema->value == 0)
{
list_insert_ordered(&sema->waiters, &thread_current ()->elem,
priority_more, NULL);
list_push_back (&sema->waiters, &thread_current ()->elem);
thread_block ();
}
sema->value--;
@@ -114,9 +113,12 @@ 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));
if (!list_empty (&sema->waiters))
{
struct list_elem *e = list_min (&sema->waiters, priority_more, NULL);
list_remove (e);
thread_unblock (list_entry (e, struct thread, elem));
}
sema->value++;
intr_set_level (old_level);