diff --git a/src/threads/synch.c b/src/threads/synch.c index 6d71c83..027018e 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -265,6 +265,18 @@ lock_release (struct lock *lock) ASSERT (lock != NULL); ASSERT (lock_held_by_current_thread (lock)); + struct thread *current_thread = thread_current (); + struct list_elem *tail = list_tail (¤t_thread->donors_list); + for (struct list_elem *e = list_begin (¤t_thread->donors_list); + e != tail; e = e->next) + { + struct thread *donor = list_entry (e, struct thread, donor_elem); + if (donor->waiting_lock == lock) + list_remove (e); + } + + thread_recalculate_priority (); + lock->holder = NULL; sema_up (&lock->semaphore); } diff --git a/src/threads/thread.c b/src/threads/thread.c index b7bab5b..ed717e3 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -408,6 +408,13 @@ thread_get_priority (void) return thread_current ()->priority; } +/* Recalculates the effective priority of the current thread. */ +void +thread_recalculate_priority (void) +{ + barrier (); +}; + /* Sets the current thread's nice value to NICE. */ void thread_set_nice (int nice UNUSED) diff --git a/src/threads/thread.h b/src/threads/thread.h index 083a5ab..b3c1006 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -144,6 +144,7 @@ bool priority_more (const struct list_elem *a_, const struct list_elem *b_, void *aux UNUSED); int thread_get_priority (void); void thread_set_priority (int); +void thread_recalculate_priority (void); int thread_get_nice (void); void thread_set_nice (int);