From 4df3c98225a4aea76119f805a75abfc63e7d4356 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Sat, 26 Nov 2022 01:49:55 +0530 Subject: [PATCH] Add double-insertion debug check to `InsertThread` This is a cause for a large amount of scheduler bugs so we should generally check for this on debug builds as it is a fairly easy way to check for issues for some performance cost. --- app/src/main/cpp/skyline/kernel/scheduler.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/cpp/skyline/kernel/scheduler.cpp b/app/src/main/cpp/skyline/kernel/scheduler.cpp index 41eb3290..ed9dc5b1 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.cpp +++ b/app/src/main/cpp/skyline/kernel/scheduler.cpp @@ -95,6 +95,16 @@ namespace skyline::kernel { thread->scheduleCondition.wait(lock, [&]() { return !thread->isPaused; }); } + #ifndef NDEBUG + // Scan the queue for the same thread to prevent double insertion + for (auto &residentThread : core.queue) { + if (residentThread == thread) { + Logger::Error("T{} already exists in C{}", thread->id, core.id); + Logger::EmulationContext.Flush(); + } + } + #endif + auto nextThread{std::upper_bound(core.queue.begin(), core.queue.end(), thread->priority.load(), type::KThread::IsHigherPriority)}; if (nextThread == core.queue.begin()) { if (nextThread != core.queue.end()) {