From 7aec2e6862d74a7e864063d504097e3c278f1fea Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Tue, 22 Oct 2024 21:15:30 +0100 Subject: [PATCH] Refactor donate_priority to include comments explaining its purpose and logic w/ S --- src/threads/synch.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/threads/synch.c b/src/threads/synch.c index 9900748..3dc15cd 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -194,16 +194,25 @@ lock_init (struct lock *lock) sema_init (&lock->semaphore, 1); } +/* Allows for the donor to donate its priority to donee, iteratively + propagating the donation in the case of chains in the wait-for graph. + Also keeps track of the donation by updating the donors list. */ static void donate_priority (struct thread *donor, struct thread *donee) { list_push_back (&donee->donors_list, &donor->donor_elem); while (donee != NULL) { + /* Stop propagation of donation once a donee is reached that has + a higher effective priority (as its donees can't have less + priority than that being donated). */ if (donor->priority <= donee->priority) break; donee->priority = donor->priority; + + /* Also stop propagation of donation once a donee is reached with + no donees of its own (sink node in WFG). */ if (donee->waiting_lock == NULL) donee = NULL; else