Skip to content

Commit

Permalink
ThreadManager: Removes IdleWaitCV
Browse files Browse the repository at this point in the history
We can't currently guarantee this condition_variable is always unlocked
without more major refactoring. This was causing GDB to wait forever.
  • Loading branch information
Sonicadvance1 committed Apr 19, 2024
1 parent eb345ba commit a86d51d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class ThreadManager final {
// Thread idling support.
bool Running {};
std::mutex IdleWaitMutex;
std::condition_variable IdleWaitCV;
std::atomic<uint32_t> IdleWaitRefCount {};

void HandleThreadDeletion(FEXCore::Core::InternalThreadState* Thread);
Expand Down
15 changes: 5 additions & 10 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void ThreadManager::HandleThreadDeletion(FEXCore::Core::InternalThreadState* Thr

CTX->DestroyThread(Thread);
--IdleWaitRefCount;
IdleWaitCV.notify_all();
}

void ThreadManager::NotifyPause() {
Expand Down Expand Up @@ -102,8 +101,8 @@ void ThreadManager::WaitForThreadsToRun() {
}

// Spin while waiting for the threads to start up
std::unique_lock<std::mutex> lk(IdleWaitMutex);
IdleWaitCV.wait(lk, [this, NumThreads] { return IdleWaitRefCount.load() >= NumThreads; });
while (IdleWaitRefCount.load() < NumThreads)
;

Running = true;
}
Expand Down Expand Up @@ -166,18 +165,14 @@ void ThreadManager::SleepThread(FEXCore::Context::Context* CTX, FEXCore::Core::C
auto Thread = Frame->Thread;

--IdleWaitRefCount;
IdleWaitCV.notify_all();

Thread->RunningEvents.ThreadSleeping = true;
Thread->RunningEvents.Running = false;

// Go to sleep
Thread->StartRunning.Wait();

Thread->RunningEvents.Running = true;
++IdleWaitRefCount;
Thread->RunningEvents.ThreadSleeping = false;

IdleWaitCV.notify_all();
}

void ThreadManager::UnlockAfterFork(FEXCore::Core::InternalThreadState* LiveThread, bool Child) {
Expand Down Expand Up @@ -225,8 +220,8 @@ void ThreadManager::UnlockAfterFork(FEXCore::Core::InternalThreadState* LiveThre
}

void ThreadManager::WaitForIdle() {
std::unique_lock<std::mutex> lk(IdleWaitMutex);
IdleWaitCV.wait(lk, [this] { return IdleWaitRefCount.load() == 0; });
while (IdleWaitRefCount.load() != 0)
;

Running = false;
}
Expand Down

0 comments on commit a86d51d

Please sign in to comment.