diff options
Diffstat (limited to 'threads/synch.c')
| -rw-r--r-- | threads/synch.c | 20 |
1 files changed, 6 insertions, 14 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 | |||
| 116 | sema_up (struct semaphore *sema) | 116 | sema_up (struct semaphore *sema) |
| 117 | { | 117 | { |
| 118 | enum intr_level old_level; | 118 | enum intr_level old_level; |
| 119 | bool yield = false; | 119 | struct thread *t = NULL; |
| 120 | 120 | ||
| 121 | ASSERT (sema != NULL); | 121 | ASSERT (sema != NULL); |
| 122 | 122 | ||
| 123 | old_level = intr_disable (); | 123 | old_level = intr_disable (); |
| 124 | if (!list_empty (&sema->waiters)) | 124 | while (!list_empty (&sema->waiters)) |
| 125 | { | 125 | { |
| 126 | struct thread *t = list_entry (list_pop_front (&sema->waiters), | 126 | t = list_entry (list_pop_front (&sema->waiters), struct thread, elem); |
| 127 | struct thread, elem); | ||
| 128 | thread_unblock (t); | 127 | thread_unblock (t); |
| 129 | /* thread_unblock() doesn't yield so check if there's a need */ | ||
| 130 | if (t->priority > thread_current ()->priority) | ||
| 131 | yield = true; | ||
| 132 | } | 128 | } |
| 133 | sema->value++; | 129 | sema->value++; |
| 134 | intr_set_level (old_level); | 130 | intr_set_level (old_level); |
| 135 | 131 | ||
| 136 | if (yield) | 132 | /* thread_unblock() doesn't yield so check if there's a need */ |
| 133 | if (t != NULL && t->priority > thread_current ()->priority) | ||
| 137 | thread_yield(); | 134 | thread_yield(); |
| 138 | } | 135 | } |
| 139 | 136 | ||
| @@ -228,8 +225,6 @@ lock_acquire (struct lock *lock) | |||
| 228 | 225 | ||
| 229 | if (lock->holder != NULL) | 226 | if (lock->holder != NULL) |
| 230 | { | 227 | { |
| 231 | //printf("[%d] acquire: lock=%p prio=%d\n", cur->tid, lock, cur->priority); | ||
| 232 | |||
| 233 | /* check for a possible priority donation */ | 228 | /* check for a possible priority donation */ |
| 234 | if (cur->priority > lock->priority) | 229 | if (cur->priority > lock->priority) |
| 235 | { | 230 | { |
| @@ -291,18 +286,15 @@ lock_release (struct lock *lock) | |||
| 291 | ASSERT (lock_held_by_current_thread (lock)); | 286 | ASSERT (lock_held_by_current_thread (lock)); |
| 292 | 287 | ||
| 293 | lock->holder = NULL; | 288 | lock->holder = NULL; |
| 294 | //lock->priority = we don't care as the next lock_acquire ()-call does | 289 | //lock->priority = we don't care as the next lock_acquire()-call does |
| 295 | sema_up (&lock->semaphore); | 290 | sema_up (&lock->semaphore); |
| 296 | 291 | ||
| 297 | /* we don't hold the lock any longer so remove it from the lock list */ | 292 | /* we don't hold the lock any longer so remove it from the lock list */ |
| 298 | list_remove (&lock->elem); | 293 | list_remove (&lock->elem); |
| 299 | 294 | ||
| 300 | if (list_empty (&cur->locks)) | 295 | if (list_empty (&cur->locks)) |
| 301 | { | ||
| 302 | //printf("[%d] restoring prio from %d to %d\n", cur->tid, cur->priority, cur->saved_priority); | ||
| 303 | /* we don't hold another lock so restore our base priority */ | 296 | /* we don't hold another lock so restore our base priority */ |
| 304 | thread_donation_pass_back (); | 297 | thread_donation_pass_back (); |
| 305 | } | ||
| 306 | else | 298 | else |
| 307 | { | 299 | { |
| 308 | /* we still hold at least one lock so change our priority to the priority of the lock */ | 300 | /* we still hold at least one lock so change our priority to the priority of the lock */ |
