From 2aaf7251b5191920d0880010c1cb30fb56f92c14 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 10 May 2012 02:28:35 +0200 Subject: fix sema_up() and hence the priority-sema testcase => 2/18 failed + some minor documentation and cleanup stuff --- threads/synch.c | 20 ++++++-------------- threads/thread.h | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/threads/synch.c b/threads/synch.c index 92008ef..2cb4805 100644 --- a/threads/synch.c +++ b/threads/synch.c @@ -116,24 +116,21 @@ void sema_up (struct semaphore *sema) { enum intr_level old_level; - bool yield = false; + struct thread *t = NULL; ASSERT (sema != NULL); old_level = intr_disable (); - if (!list_empty (&sema->waiters)) + while (!list_empty (&sema->waiters)) { - struct thread *t = list_entry (list_pop_front (&sema->waiters), - struct thread, elem); + t = list_entry (list_pop_front (&sema->waiters), struct thread, elem); thread_unblock (t); - /* thread_unblock() doesn't yield so check if there's a need */ - if (t->priority > thread_current ()->priority) - yield = true; } sema->value++; intr_set_level (old_level); - if (yield) + /* thread_unblock() doesn't yield so check if there's a need */ + if (t != NULL && t->priority > thread_current ()->priority) thread_yield(); } @@ -228,8 +225,6 @@ lock_acquire (struct lock *lock) if (lock->holder != NULL) { - //printf("[%d] acquire: lock=%p prio=%d\n", cur->tid, lock, cur->priority); - /* check for a possible priority donation */ if (cur->priority > lock->priority) { @@ -291,18 +286,15 @@ 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 as 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 */ list_remove (&lock->elem); if (list_empty (&cur->locks)) - { - //printf("[%d] restoring prio from %d to %d\n", cur->tid, cur->priority, cur->saved_priority); /* we don't hold another lock so restore our base priority */ thread_donation_pass_back (); - } else { /* we still hold at least one lock so change our priority to the priority of the lock */ diff --git a/threads/thread.h b/threads/thread.h index 8bc6512..8cfafe6 100644 --- a/threads/thread.h +++ b/threads/thread.h @@ -110,7 +110,7 @@ struct thread int is_donated; /* flag if threads priority has been donated by another thread */ int saved_priority; /* saved base priority in case of priority dontation */ - struct list locks; /* list of locks we currently hold */ + struct list locks; /* list of locks the thread currently holds */ }; /* If false (default), use round-robin scheduler. -- cgit v1.2.3