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.
This commit is contained in:
PixelyIon 2022-11-26 01:49:55 +05:30 committed by Mark Collins
parent 5694c9b34b
commit 4df3c98225

View File

@ -95,6 +95,16 @@ namespace skyline::kernel {
thread->scheduleCondition.wait(lock, [&]() { return !thread->isPaused; }); 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)}; 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.begin()) {
if (nextThread != core.queue.end()) { if (nextThread != core.queue.end()) {