Skip to content

Commit

Permalink
Fix: Prevent log spam when a deadlock is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Aug 2, 2021
1 parent d950346 commit aa5b9e2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChromePatcherDll/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,19 @@ namespace ChromePatch {
// I cannot use patchThread.join here, because it causes deadlocks
HANDLE patchHandle = patchThread.native_handle();
const time_t waitTime = std::time(nullptr);
bool hasNoticedTimeout = false;

while(WaitForSingleObject(patchHandle, 0) != WAIT_OBJECT_0) {
// Active waiting required to prevent deadlocks

if(hasNoticedTimeout) {
continue;
}

if(waitTime + (simdCpuSupport ? 1 : 5) < std::time(nullptr)) { // 1 or 5 seconds timeout
std::cout << "Patch Thread " << patchHandle << " timeouted! Resuming all other threads. (This is a race condition now)" << std::endl;
ResumeOtherThreads();
hasNoticedTimeout = true;
}
}

Expand Down

0 comments on commit aa5b9e2

Please sign in to comment.