From 9b19a84ed640cb15e6ca87ddc025c90d78a5fbdc Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 11 May 2012 20:48:58 +0200 Subject: * fix possible race in thread_set_priority * fill in same parts of proj1.txt * use thread_get_priority() whenever possible --- threads/synch.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'threads/synch.c') diff --git a/threads/synch.c b/threads/synch.c index 98905b1..a1b7549 100644 --- a/threads/synch.c +++ b/threads/synch.c @@ -128,7 +128,7 @@ sema_up (struct semaphore *sema) list_sort (&sema->waiters, &thread_priority_cmp_greater, NULL); struct thread *t = list_entry (list_pop_front (&sema->waiters), struct thread, elem); /* thread_unblock() doesn't yield so check if there's a need */ - if (t->priority > thread_current ()->priority) + if (t->priority > thread_get_priority ()) yield = true; thread_unblock (t); } @@ -240,10 +240,10 @@ lock_acquire (struct lock *lock) while (blocked_lock != NULL && blocked_lock->holder != NULL) { /* check for a possible priority donation */ - if (cur->priority > blocked_lock->priority) + if (thread_get_priority () > blocked_lock->priority) { /* the new priority of this lock is our own priority */ - blocked_lock->priority = cur->priority; + blocked_lock->priority = thread_get_priority (); /* the lock priority changed so we need to sort the lock list of the lock holder */ list_remove (&blocked_lock->elem); @@ -264,7 +264,7 @@ lock_acquire (struct lock *lock) cur->blocked_lock = NULL; /* the priority of this lock is our own priority */ - lock->priority = cur->priority; + lock->priority = thread_get_priority (); /* save the locks we hold in descending order of their priority */ list_insert_ordered (&lock->holder->locks, &lock->elem, @@ -305,7 +305,7 @@ lock_release (struct lock *lock) ASSERT (lock_held_by_current_thread (lock)); lock->holder = NULL; - //lock->priority = we don't care as the next lock_acquire()-call does + //lock->priority = we don't care since the next lock_acquire()-call does sema_up (&lock->semaphore); /* we don't hold the lock any longer so remove it from the lock list */ @@ -424,9 +424,9 @@ cond_signal (struct condition *cond, struct lock *lock UNUSED) this is the same as with sema_down()/sema_up() */ if (!list_empty (&cond->waiters)) { - list_sort (&cond->waiters, &semaphore_priority_cmp_greater, NULL); - sema_up (&list_entry (list_pop_front (&cond->waiters), - struct semaphore_elem, elem)->semaphore); + list_sort (&cond->waiters, &semaphore_priority_cmp_greater, NULL); + sema_up (&list_entry (list_pop_front (&cond->waiters), + struct semaphore_elem, elem)->semaphore); } } -- cgit v1.2.3