mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-19 06:30:07 +08:00
fix: RunGuard not works on Qt6 (#1095)
* Revert "fix: RunGuard not works on Qt6"
This reverts commit 32ef100cf3.
* fix: RunGuard not works on Qt6
This commit is contained in:
parent
beb87352ae
commit
1b078a8aab
19
3rdparty/RunGuard.hpp
vendored
19
3rdparty/RunGuard.hpp
vendored
@ -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,12 @@ 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();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user