File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -58,28 +58,34 @@ RunGuard::~RunGuard() {
58
58
}
59
59
60
60
bool RunGuard::isAnotherRunning (quint64 *data_out) {
61
- if (sharedMem.isAttached ())
61
+ if (sharedMem.isAttached ()) {
62
62
return false ;
63
+ }
63
64
64
65
memLock.acquire ();
65
- const bool isRunning = sharedMem.attach ();
66
- if (isRunning) {
66
+ const bool isRunning = sharedMem.create (sizeof (quint64));if (!isRunning) {
67
67
if (data_out != nullptr ) {
68
68
memcpy (data_out, sharedMem.data (), sizeof (quint64));
69
69
}
70
70
sharedMem.detach ();
71
71
}
72
72
memLock.release ();
73
73
74
- return isRunning;
74
+ return ! isRunning;
75
75
}
76
76
77
+
77
78
bool RunGuard::tryToRun (quint64 *data_in) {
78
79
if (isAnotherRunning (nullptr )) // Extra check
79
80
return false ;
80
81
81
82
memLock.acquire ();
82
- const bool result = sharedMem.create (sizeof (quint64));
83
+
84
+ bool result = sharedMem.attach ();
85
+ // if success attach, attach return false but the error is NoError, magic, love from qt6
86
+ // qt docs: If false is returned, call error() to determine which error occurred.
87
+ if (!result) if (sharedMem.error () == QSharedMemory::NoError) result = true ;
88
+
83
89
if (result) memcpy (sharedMem.data (), data_in, sizeof (quint64));
84
90
memLock.release ();
85
91
You can’t perform that action at this time.
0 commit comments