Implement priority donation helper function with propagation, w/ T

This commit is contained in:
sBubshait
2024-10-20 19:42:35 +01:00
parent f98e4bc81c
commit 343ac55d37
3 changed files with 23 additions and 1 deletions

View File

@@ -188,7 +188,21 @@ lock_init (struct lock *lock)
}
static void
donate_priority (struct thread *donor, struct thread *donee);
donate_priority (struct thread *donor, struct thread *donee) {
while (donee != NULL)
{
if (donor->priority <= donee->priority)
break;
donee->priority = donor->priority;
if (donee->waiting_lock == NULL)
donee = NULL;
else
donee = donee->waiting_lock->holder;
}
ready_list_reorder ();
}
/* Acquires LOCK, sleeping until it becomes available if
necessary. The lock must not already be held by the current

View File

@@ -439,6 +439,12 @@ thread_get_recent_cpu (void)
return 0;
}
void
ready_list_reorder (void)
{
list_sort (&ready_list, priority_more, NULL);
}
/* Idle thread. Executes when no other thread is ready to run.
The idle thread is initially put on the ready list by

View File

@@ -150,6 +150,8 @@ void thread_set_nice (int);
int thread_get_recent_cpu (void);
int thread_get_load_avg (void);
void ready_list_reorder (void);
/* Returns true iff the priority of the first list element's thread is greater
than that of the second list element's thread. */
list_less_func thread_priority_greater;