summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--threads/synch.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/threads/synch.c b/threads/synch.c
index d7e5e39..98905b1 100644
--- a/threads/synch.c
+++ b/threads/synch.c
@@ -34,6 +34,8 @@
34 34
35static bool lock_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b, 35static bool lock_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b,
36 void *AUX UNUSED); 36 void *AUX UNUSED);
37static bool semaphore_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b,
38 void *aux UNUSED);
37 39
38/* Initializes semaphore SEMA to VALUE. A semaphore is a 40/* Initializes semaphore SEMA to VALUE. A semaphore is a
39 nonnegative integer along with two atomic operators for 41 nonnegative integer along with two atomic operators for
@@ -351,6 +353,16 @@ cond_init (struct condition *cond)
351 list_init (&cond->waiters); 353 list_init (&cond->waiters);
352} 354}
353 355
356/* comparison function for our descending ordered condition waiters list. */
357static bool
358semaphore_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b,
359 void *aux UNUSED)
360{
361 const struct semaphore_elem *s1 = list_entry (a, struct semaphore_elem, elem);
362 const struct semaphore_elem *s2 = list_entry (b, struct semaphore_elem, elem);
363 return (s1->thread->priority > s2->thread->priority);
364}
365
354/* Atomically releases LOCK and waits for COND to be signaled by 366/* Atomically releases LOCK and waits for COND to be signaled by
355 some other piece of code. After COND is signaled, LOCK is 367 some other piece of code. After COND is signaled, LOCK is
356 reacquired before returning. LOCK must be held before calling 368 reacquired before returning. LOCK must be held before calling
@@ -386,7 +398,7 @@ cond_wait (struct condition *cond, struct lock *lock)
386 waiter.thread = thread_current (); 398 waiter.thread = thread_current ();
387 /* and add condition to our waiters list. sorting isn't useful here either. 399 /* and add condition to our waiters list. sorting isn't useful here either.
388 see sema_up()/cond_signal() for more details */ 400 see sema_up()/cond_signal() for more details */
389 list_push_back (&cond->waiters, &waiter->elem); 401 list_push_back (&cond->waiters, &waiter.elem);
390 lock_release (lock); 402 lock_release (lock);
391 sema_down (&waiter.semaphore); 403 sema_down (&waiter.semaphore);
392 lock_acquire (lock); 404 lock_acquire (lock);