Update set priority to reorder the list if priority is changed

This commit is contained in:
sBubshait
2024-10-17 06:38:27 +01:00
parent 949455aae5
commit dbb7fd56e3

View File

@@ -391,6 +391,15 @@ thread_set_priority (int new_priority)
enum intr_level old_level = intr_disable ();
/* If the thread is in the ready list, the list must be reordered to maintain
the priority order. */
if (thread_current ()->status == THREAD_READY) {
/* Remove from the ready list and reinsert it in priority order. */
list_remove (&thread_current ()->elem);
list_insert_ordered (&ready_list, &thread_current ()->elem, priority_more,
NULL);
}
if (new_priority < old_priority && !list_empty (&ready_list)) {
/* If the new priority is lower than the old priority, check if the current
thread no longer has the highest priority. If it doesn't, yield the CPU.