From d9b957263140170fb38b41d8dccd35e593ce2711 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Tue, 22 Oct 2024 19:49:53 +0100 Subject: [PATCH] Fix Bug in recalculating priority, uses 'elem' instead of 'donor_elem', w/ T --- src/threads/thread.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index 379c6d7..c4722a9 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -70,6 +70,8 @@ static void *alloc_frame (struct thread *, size_t size); static void schedule (void); void thread_schedule_tail (struct thread *prev); static tid_t allocate_tid (void); +static bool donor_priority_less (const struct list_elem *a_, + const struct list_elem *b_, void *aux UNUSED); /* Initializes the threading system by transforming the code that's currently running into a thread. This can't work in @@ -370,6 +372,19 @@ priority_more (const struct list_elem *a_, const struct list_elem *b_, return a->priority > b->priority; } +/* Function that compares the two threads associated with the provided + pointers to their 'donor_elem' member. Returns true if the thread associated + with a_ has a lower priority than that of b_. */ +static bool +donor_priority_less (const struct list_elem *a_, const struct list_elem *b_, + void *aux UNUSED) +{ + struct thread *a = list_entry (a_, struct thread, donor_elem); + struct thread *b = list_entry (b_, struct thread, donor_elem); + + return a->priority < b->priority; +} + /* Sets the current thread's base priority to new_base_priority. Updates the current thread's effective priority if necessary. */ void @@ -408,7 +423,7 @@ thread_recalculate_priority (void) if (!list_empty (&t->donors_list)) { int max_donated_priority = - list_entry (list_max (&t->donors_list, priority_more, NULL), + list_entry (list_max (&t->donors_list, donor_priority_less, NULL), struct thread, donor_elem)->priority; if (max_donated_priority > t->priority)