From aa5b9e2f849ab1532773d28b5bdc01f99d4de1a9 Mon Sep 17 00:00:00 2001 From: Ceiridge Date: Tue, 3 Aug 2021 01:38:37 +0200 Subject: [PATCH] Fix: Prevent log spam when a deadlock is detected --- ChromePatcherDll/patches.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChromePatcherDll/patches.cpp b/ChromePatcherDll/patches.cpp index 4cc4ae2..fe761fb 100644 --- a/ChromePatcherDll/patches.cpp +++ b/ChromePatcherDll/patches.cpp @@ -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; } }