Merge 'task1/priority-donation' into 'master' #14

Merged
sb3923 merged 66 commits from task1/priority-donation into master 2024-10-23 16:15:45 +00:00
4 changed files with 151 additions and 10 deletions
Showing only changes of commit 343ac55d37 - Show all commits

View File

@@ -188,7 +188,21 @@ lock_init (struct lock *lock)
} }
static void 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 /* Acquires LOCK, sleeping until it becomes available if
necessary. The lock must not already be held by the current necessary. The lock must not already be held by the current

View File

@@ -439,6 +439,12 @@ thread_get_recent_cpu (void)
return 0; 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. /* Idle thread. Executes when no other thread is ready to run.
The idle thread is initially put on the ready list by 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_recent_cpu (void);
int thread_get_load_avg (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 /* Returns true iff the priority of the first list element's thread is greater
than that of the second list element's thread. */ than that of the second list element's thread. */
list_less_func thread_priority_greater; list_less_func thread_priority_greater;