From 5549b9c0cb73d2c652566f737674e23bd61d5f44 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Tue, 22 Oct 2024 20:52:52 +0100 Subject: [PATCH] Refactor thread recalculate priority to add comments for clarity, w/ T --- src/threads/thread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/threads/thread.c b/src/threads/thread.c index 79dd339..ff66100 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -419,12 +419,16 @@ thread_recalculate_priority (void) struct thread *t = thread_current (); t->priority = t->base_priority; + /* If there are no donors to the current thread, then the effective + priority is just the base priority. */ if (!list_empty (&t->donors_list)) { int max_donated_priority = list_entry (list_max (&t->donors_list, donor_priority_less, NULL), struct thread, donor_elem)->priority; + /* The effective priority is the max donated priority if this is + higher than the base priority. */ if (max_donated_priority > t->priority) t->priority = max_donated_priority; }