diff options
| author | manuel <manuel@mausz.at> | 2012-05-11 20:48:58 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-05-11 20:48:58 +0200 |
| commit | 9b19a84ed640cb15e6ca87ddc025c90d78a5fbdc (patch) | |
| tree | 54345ae3ba366d1a4663e93b6b883e842f7a3918 /threads/synch.c | |
| parent | 4571d64e74dadd1b2169e8cd276f8a298decd5f0 (diff) | |
| download | progos-9b19a84ed640cb15e6ca87ddc025c90d78a5fbdc.tar.gz progos-9b19a84ed640cb15e6ca87ddc025c90d78a5fbdc.tar.bz2 progos-9b19a84ed640cb15e6ca87ddc025c90d78a5fbdc.zip | |
* fix possible race in thread_set_priority
* fill in same parts of proj1.txt
* use thread_get_priority() whenever possible
Diffstat (limited to 'threads/synch.c')
| -rw-r--r-- | threads/synch.c | 16 |
1 files changed, 8 insertions, 8 deletions
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) | |||
| 128 | list_sort (&sema->waiters, &thread_priority_cmp_greater, NULL); | 128 | list_sort (&sema->waiters, &thread_priority_cmp_greater, NULL); |
| 129 | struct thread *t = list_entry (list_pop_front (&sema->waiters), struct thread, elem); | 129 | struct thread *t = list_entry (list_pop_front (&sema->waiters), struct thread, elem); |
| 130 | /* thread_unblock() doesn't yield so check if there's a need */ | 130 | /* thread_unblock() doesn't yield so check if there's a need */ |
| 131 | if (t->priority > thread_current ()->priority) | 131 | if (t->priority > thread_get_priority ()) |
| 132 | yield = true; | 132 | yield = true; |
| 133 | thread_unblock (t); | 133 | thread_unblock (t); |
| 134 | } | 134 | } |
| @@ -240,10 +240,10 @@ lock_acquire (struct lock *lock) | |||
| 240 | while (blocked_lock != NULL && blocked_lock->holder != NULL) | 240 | while (blocked_lock != NULL && blocked_lock->holder != NULL) |
| 241 | { | 241 | { |
| 242 | /* check for a possible priority donation */ | 242 | /* check for a possible priority donation */ |
| 243 | if (cur->priority > blocked_lock->priority) | 243 | if (thread_get_priority () > blocked_lock->priority) |
| 244 | { | 244 | { |
| 245 | /* the new priority of this lock is our own priority */ | 245 | /* the new priority of this lock is our own priority */ |
| 246 | blocked_lock->priority = cur->priority; | 246 | blocked_lock->priority = thread_get_priority (); |
| 247 | 247 | ||
| 248 | /* the lock priority changed so we need to sort the lock list of the lock holder */ | 248 | /* the lock priority changed so we need to sort the lock list of the lock holder */ |
| 249 | list_remove (&blocked_lock->elem); | 249 | list_remove (&blocked_lock->elem); |
| @@ -264,7 +264,7 @@ lock_acquire (struct lock *lock) | |||
| 264 | cur->blocked_lock = NULL; | 264 | cur->blocked_lock = NULL; |
| 265 | 265 | ||
| 266 | /* the priority of this lock is our own priority */ | 266 | /* the priority of this lock is our own priority */ |
| 267 | lock->priority = cur->priority; | 267 | lock->priority = thread_get_priority (); |
| 268 | 268 | ||
| 269 | /* save the locks we hold in descending order of their priority */ | 269 | /* save the locks we hold in descending order of their priority */ |
| 270 | list_insert_ordered (&lock->holder->locks, &lock->elem, | 270 | list_insert_ordered (&lock->holder->locks, &lock->elem, |
| @@ -305,7 +305,7 @@ lock_release (struct lock *lock) | |||
| 305 | ASSERT (lock_held_by_current_thread (lock)); | 305 | ASSERT (lock_held_by_current_thread (lock)); |
| 306 | 306 | ||
| 307 | lock->holder = NULL; | 307 | lock->holder = NULL; |
| 308 | //lock->priority = we don't care as the next lock_acquire()-call does | 308 | //lock->priority = we don't care since the next lock_acquire()-call does |
| 309 | sema_up (&lock->semaphore); | 309 | sema_up (&lock->semaphore); |
| 310 | 310 | ||
| 311 | /* we don't hold the lock any longer so remove it from the lock list */ | 311 | /* 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) | |||
| 424 | this is the same as with sema_down()/sema_up() */ | 424 | this is the same as with sema_down()/sema_up() */ |
| 425 | if (!list_empty (&cond->waiters)) | 425 | if (!list_empty (&cond->waiters)) |
| 426 | { | 426 | { |
| 427 | list_sort (&cond->waiters, &semaphore_priority_cmp_greater, NULL); | 427 | list_sort (&cond->waiters, &semaphore_priority_cmp_greater, NULL); |
| 428 | sema_up (&list_entry (list_pop_front (&cond->waiters), | 428 | sema_up (&list_entry (list_pop_front (&cond->waiters), |
| 429 | struct semaphore_elem, elem)->semaphore); | 429 | struct semaphore_elem, elem)->semaphore); |
| 430 | } | 430 | } |
| 431 | } | 431 | } |
| 432 | 432 | ||
