From b87f451746807cc294fad615499025e2371df780 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 18 Jun 2021 17:22:04 +0100 Subject: [PATCH] Handle empty core queues in Scheduler::UpdatePriority If the queue is empty then begin() == end() leading to ArmPreemptionTimer being called on an unscheduled thread. --- app/src/main/cpp/skyline/kernel/scheduler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/skyline/kernel/scheduler.cpp b/app/src/main/cpp/skyline/kernel/scheduler.cpp index 8cbda4c5..40fa90da 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.cpp +++ b/app/src/main/cpp/skyline/kernel/scheduler.cpp @@ -258,6 +258,9 @@ namespace skyline::kernel { std::unique_lock coreLock(core->mutex); auto currentIt{std::find(core->queue.begin(), core->queue.end(), thread)}, nextIt{std::next(currentIt)}; + if (currentIt == core->queue.end()) + return; + if (currentIt == core->queue.begin()) { // Alternatively, if it's currently running then we'd just want to yield if there's a higher priority thread to run instead if (nextIt != core->queue.end() && (*nextIt)->priority < thread->priority) { @@ -272,7 +275,7 @@ namespace skyline::kernel { // If the thread no longer needs to be preempted due to its new priority then disarm its preemption timer thread->DisarmPreemptionTimer(); } - } else if (currentIt != core->queue.end() && (thread->priority < (*std::prev(currentIt))->priority || (nextIt != core->queue.end() && thread->priority > (*nextIt)->priority))) { + } else if (thread->priority < (*std::prev(currentIt))->priority || (nextIt != core->queue.end() && thread->priority > (*nextIt)->priority)) { // If the thread is in the queue and it's position is affected by the priority change then need to remove and re-insert the thread core->queue.erase(currentIt);