Update releasing of locks to update donation information w/ S

This commit is contained in:
Themis Demetriades
2024-10-20 20:17:27 +01:00
parent ee0cf632b9
commit 8e20884a23
3 changed files with 20 additions and 0 deletions

View File

@@ -265,6 +265,18 @@ lock_release (struct lock *lock)
ASSERT (lock != NULL); ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock)); ASSERT (lock_held_by_current_thread (lock));
struct thread *current_thread = thread_current ();
struct list_elem *tail = list_tail (&current_thread->donors_list);
for (struct list_elem *e = list_begin (&current_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; lock->holder = NULL;
sema_up (&lock->semaphore); sema_up (&lock->semaphore);
} }

View File

@@ -408,6 +408,13 @@ thread_get_priority (void)
return thread_current ()->priority; 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. */ /* Sets the current thread's nice value to NICE. */
void void
thread_set_nice (int nice UNUSED) thread_set_nice (int nice UNUSED)

View File

@@ -144,6 +144,7 @@ bool priority_more (const struct list_elem *a_, const struct list_elem *b_,
void *aux UNUSED); void *aux UNUSED);
int thread_get_priority (void); int thread_get_priority (void);
void thread_set_priority (int); void thread_set_priority (int);
void thread_recalculate_priority (void);
int thread_get_nice (void); int thread_get_nice (void);
void thread_set_nice (int); void thread_set_nice (int);