From 4571d64e74dadd1b2169e8cd276f8a298decd5f0 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 11 May 2012 15:24:08 +0200 Subject: accidentally removed semaphore_priority_cmp_greater --- threads/synch.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'threads') 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 @@ static bool lock_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b, void *AUX UNUSED); +static bool semaphore_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b, + void *aux UNUSED); /* Initializes semaphore SEMA to VALUE. A semaphore is a nonnegative integer along with two atomic operators for @@ -351,6 +353,16 @@ cond_init (struct condition *cond) list_init (&cond->waiters); } +/* comparison function for our descending ordered condition waiters list. */ +static bool +semaphore_priority_cmp_greater(const struct list_elem *a, const struct list_elem *b, + void *aux UNUSED) +{ + const struct semaphore_elem *s1 = list_entry (a, struct semaphore_elem, elem); + const struct semaphore_elem *s2 = list_entry (b, struct semaphore_elem, elem); + return (s1->thread->priority > s2->thread->priority); +} + /* Atomically releases LOCK and waits for COND to be signaled by some other piece of code. After COND is signaled, LOCK is reacquired before returning. LOCK must be held before calling @@ -386,7 +398,7 @@ cond_wait (struct condition *cond, struct lock *lock) waiter.thread = thread_current (); /* and add condition to our waiters list. sorting isn't useful here either. see sema_up()/cond_signal() for more details */ - list_push_back (&cond->waiters, &waiter->elem); + list_push_back (&cond->waiters, &waiter.elem); lock_release (lock); sema_down (&waiter.semaphore); lock_acquire (lock); -- cgit v1.2.3