From f746888c56f760b77ce2970e3092ab9b15f0ff29 Mon Sep 17 00:00:00 2001 From: BlacAmDK Date: Tue, 5 Dec 2023 19:51:12 +0800 Subject: [PATCH 1/2] Revert "fix: RunGuard not works on Qt6" This reverts commit 32ef100cf36076cf672714c68120e0a9141d0106. --- 3rdparty/RunGuard.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/3rdparty/RunGuard.hpp b/3rdparty/RunGuard.hpp index 77d97e2ac..f24c798c9 100644 --- a/3rdparty/RunGuard.hpp +++ b/3rdparty/RunGuard.hpp @@ -58,12 +58,12 @@ RunGuard::~RunGuard() { } bool RunGuard::isAnotherRunning(quint64 *data_out) { - if (sharedMem.isAttached()) { + if (sharedMem.isAttached()) return false; - } memLock.acquire(); - const bool isRunning = sharedMem.create(sizeof(quint64));if (!isRunning) { + const bool isRunning = sharedMem.attach(); + if (isRunning) { if (data_out != nullptr) { memcpy(data_out, sharedMem.data(), sizeof(quint64)); } @@ -71,21 +71,15 @@ bool RunGuard::isAnotherRunning(quint64 *data_out) { } memLock.release(); - return !isRunning; + return isRunning; } - bool RunGuard::tryToRun(quint64 *data_in) { if (isAnotherRunning(nullptr)) // Extra check return false; memLock.acquire(); - - bool result = sharedMem.attach(); - // if success attach, attach return false but the error is NoError, magic, love from qt6 - // qt docs: If false is returned, call error() to determine which error occurred. - if (!result) if (sharedMem.error() == QSharedMemory::NoError) result = true; - + const bool result = sharedMem.create(sizeof(quint64)); if (result) memcpy(sharedMem.data(), data_in, sizeof(quint64)); memLock.release(); From d64bc2b6193e50be4d25d9415477f13c91c4f9c3 Mon Sep 17 00:00:00 2001 From: BlacAmDK Date: Tue, 5 Dec 2023 21:32:53 +0800 Subject: [PATCH 2/2] fix: RunGuard not works on Qt6 --- 3rdparty/RunGuard.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/3rdparty/RunGuard.hpp b/3rdparty/RunGuard.hpp index f24c798c9..6a38d550d 100644 --- a/3rdparty/RunGuard.hpp +++ b/3rdparty/RunGuard.hpp @@ -75,9 +75,6 @@ bool RunGuard::isAnotherRunning(quint64 *data_out) { } bool RunGuard::tryToRun(quint64 *data_in) { - if (isAnotherRunning(nullptr)) // Extra check - return false; - memLock.acquire(); const bool result = sharedMem.create(sizeof(quint64)); if (result) memcpy(sharedMem.data(), data_in, sizeof(quint64));