From 6645692288931017ddb2b005bce7fe07e0b5bd4a Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Mon, 28 Nov 2022 23:33:15 +0530 Subject: [PATCH] Don't block while inserting paused threads Blocking while inserting a paused thread can lead to deadlocks where the inserting thread later resumes the paused thread. Co-authored-by: Billy Laws --- app/src/main/cpp/skyline/kernel/scheduler.cpp | 6 +++--- app/src/main/cpp/skyline/kernel/scheduler.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/kernel/scheduler.cpp b/app/src/main/cpp/skyline/kernel/scheduler.cpp index 588599d6..2ae135bb 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.cpp +++ b/app/src/main/cpp/skyline/kernel/scheduler.cpp @@ -91,9 +91,9 @@ namespace skyline::kernel { std::unique_lock lock{core.mutex}; if (thread->isPaused) { - // We cannot insert a thread that is paused, so we need to wait until it has been resumed - thread->insertThreadOnResume = false; - thread->scheduleCondition.wait(lock, [&]() { return !thread->isPaused; }); + // We cannot insert a thread that is paused, so we just let the resuming thread insert it + thread->insertThreadOnResume = true; + return; } #ifndef NDEBUG diff --git a/app/src/main/cpp/skyline/kernel/scheduler.h b/app/src/main/cpp/skyline/kernel/scheduler.h index 51e9752b..fe01a875 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.h +++ b/app/src/main/cpp/skyline/kernel/scheduler.h @@ -87,6 +87,7 @@ namespace skyline { /** * @brief Inserts the specified thread into the scheduler queue at the appropriate location based on its priority + * @note This is a non-blocking operation when the thread is paused, the thread will only be inserted when it is resumed */ void InsertThread(const std::shared_ptr &thread);