Update cond_wait to insert into waiters list in sorted order of priority
This commit is contained in:
@@ -355,7 +355,14 @@ cond_wait (struct condition *cond, struct lock *lock)
|
||||
ASSERT (lock_held_by_current_thread (lock));
|
||||
|
||||
sema_init (&waiter.semaphore, 0);
|
||||
list_push_back (&cond->waiters, &waiter.elem);
|
||||
|
||||
/* Insert the semaphore_elem into the waiters list in order of priority.
|
||||
We pass the priority of the current thread as aux to sema_priority_more
|
||||
because the thread has not been sema'd down yet (See sema_priority_more) */
|
||||
int priority = thread_current ()->priority;
|
||||
list_insert_ordered (&cond->waiters, &waiter.elem, sema_priority_more,
|
||||
&priority);
|
||||
|
||||
lock_release (lock);
|
||||
sema_down (&waiter.semaphore);
|
||||
lock_acquire (lock);
|
||||
|
||||
Reference in New Issue
Block a user