Update set priority to reorder the list if priority is changed
This commit is contained in:
@@ -391,6 +391,15 @@ thread_set_priority (int new_priority)
|
|||||||
|
|
||||||
enum intr_level old_level = intr_disable ();
|
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 (new_priority < old_priority && !list_empty (&ready_list)) {
|
||||||
/* If the new priority is lower than the old priority, check if the current
|
/* 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.
|
thread no longer has the highest priority. If it doesn't, yield the CPU.
|
||||||
|
|||||||
Reference in New Issue
Block a user