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 <blaws05@gmail.com>
This commit is contained in:
PixelyIon 2022-11-28 23:33:15 +05:30 committed by Mark Collins
parent 643f4cf864
commit 6645692288
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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<type::KThread> &thread);