From ac12ad224391cadb868c6402fd84e9321d8c4223 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 1 Aug 2022 13:26:07 +0600 Subject: [PATCH] Revert "Fix crash at exit due to a unreleased mutex." This reverts commit 80e547000673b1f8f9804a3cacbe5dc934077493. std::unique_lock is incapable of recursively locking a mutex, which is needed for multi-monitor setups. As a result it will crash/show undefined behaviour when switching renderers. Switch to instead calling endblit() after pc_close to avoid crashes; at this point the CPU thread is now terminated so the mutex no longer remains held by it. --- src/qt/qt_main.cpp | 1 + src/qt/qt_platform.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index c30304eb8..a74958511 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -289,6 +289,7 @@ int main(int argc, char* argv[]) { cpu_thread_run = 0; main_thread->join(); pc_close(nullptr); + endblit(); socket.close(); return ret; diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index d1f5318ba..527b4e2ab 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -54,7 +54,6 @@ QElapsedTimer elapsed_timer; static std::atomic_int blitmx_contention = 0; static std::recursive_mutex blitmx; -static thread_local std::unique_lock blit_lock { blitmx, std::defer_lock }; class CharPointer { public: @@ -469,17 +468,17 @@ void dynld_close(void *handle) void startblit() { blitmx_contention++; - if (blit_lock.try_lock()) { + if (blitmx.try_lock()) { return; } - blit_lock.lock(); + blitmx.lock(); } void endblit() { blitmx_contention--; - blit_lock.unlock(); + blitmx.unlock(); if (blitmx_contention > 0) { // a deadlock has been observed on linux when toggling via video_toggle_option // because the mutex is typically unfair on linux