Update condvar to use linear search due to changes in priority from donations, w/ T

This commit is contained in:
sBubshait
2024-10-22 20:25:13 +01:00
parent 21cbfc9fe0
commit 244db41434

View File

@@ -413,8 +413,7 @@ cond_wait (struct condition *cond, struct lock *lock)
ASSERT (lock_held_by_current_thread (lock)); ASSERT (lock_held_by_current_thread (lock));
sema_init (&waiter.semaphore, 0); sema_init (&waiter.semaphore, 0);
list_insert_ordered (&cond->waiters, &waiter.elem, sema_priority_more, list_push_back (&cond->waiters, &waiter.elem);
&thread_current ()->elem);
lock_release (lock); lock_release (lock);
sema_down (&waiter.semaphore); sema_down (&waiter.semaphore);
lock_acquire (lock); lock_acquire (lock);
@@ -435,9 +434,13 @@ cond_signal (struct condition *cond, struct lock *lock UNUSED)
ASSERT (!intr_context ()); ASSERT (!intr_context ());
ASSERT (lock_held_by_current_thread (lock)); ASSERT (lock_held_by_current_thread (lock));
if (!list_empty (&cond->waiters)) if (!list_empty (&cond->waiters))
sema_up (&list_entry (list_pop_front (&cond->waiters), {
struct semaphore_elem, elem)->semaphore); struct list_elem *e = list_min (&cond->waiters, sema_priority_more, NULL);
list_remove (e);
sema_up (&list_entry (e, struct semaphore_elem, elem)->semaphore);
}
} }
/* Wakes up all threads, if any, waiting on COND (protected by /* Wakes up all threads, if any, waiting on COND (protected by