From b0074c80f014ca24763dc2f561bd185f62b6c983 Mon Sep 17 00:00:00 2001 From: Themis Demetriades Date: Wed, 23 Oct 2024 13:51:07 +0100 Subject: [PATCH] Refactor ready_list_reinsert to require being called with interrupts disabled --- src/threads/synch.c | 2 ++ src/threads/thread.c | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/threads/synch.c b/src/threads/synch.c index 0649772..7dc6eaa 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -220,7 +220,9 @@ donate_priority (struct thread *donee) { /* Only the sink node of the WFG isn't waiting for a lock and could be on the ready list. Thus, as its priority changed, it must be reinserted into the list. */ + enum intr_level old_level = intr_disable (); ready_list_reinsert (donee); + intr_set_level (old_level); donee = NULL; } else diff --git a/src/threads/thread.c b/src/threads/thread.c index 178cdf9..8731b3b 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -467,20 +467,18 @@ thread_get_recent_cpu (void) /* Reinsert thread t into the ready list at its correct position in descending order of priority. Used when this thread's priority - may have changed. */ + may have changed. Must be called with interrupts disabled. */ void ready_list_reinsert (struct thread *t) { - enum intr_level old_level = intr_disable (); + ASSERT (intr_get_level () == INTR_OFF); /* If the thread isn't ready to run, do nothing. */ - if (t->status == THREAD_READY) - { - list_remove (&t->elem); - list_insert_ordered (&ready_list, &t->elem, priority_more, NULL); - } + if (t->status != THREAD_READY) + return; - intr_set_level (old_level); + list_remove (&t->elem); + list_insert_ordered (&ready_list, &t->elem, priority_more, NULL); } /* Idle thread. Executes when no other thread is ready to run.