From 42a917fc58b256ee71343231fdb6aaf3d9389e9a Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 11 Oct 2015 13:47:19 +0200 Subject: [PATCH 1/6] remove obsolete QThread::msleep completely --- src/ipc.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index 1c71d1f29..30bb3cb1f 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -188,7 +188,6 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout/*=-1*/) while (!(result = isEventAccepted(postTime))) { qApp->processEvents(); - QThread::msleep(10); if (timeout > 0 && difftime(time(0), start) >= timeout) break; } From 5ddfc2eefe35d8dff377fabb91ea5e43bbfe0cef Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 11 Oct 2015 13:49:22 +0200 Subject: [PATCH 2/6] cleanup inheritance QThread --> QObject and includes IPC is actually not running in a thread; And if, QThread should not be inherited. --- src/ipc.cpp | 3 ++- src/ipc.h | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index 30bb3cb1f..5197f7610 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -19,8 +19,9 @@ #include "src/ipc.h" #include "src/persistence/settings.h" -#include #include +#include +#include #include #include diff --git a/src/ipc.h b/src/ipc.h index 736343332..325579f88 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -21,20 +21,19 @@ #ifndef IPC_H #define IPC_H +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include using IPCEventHandler = std::function; #define IPC_PROTOCOL_VERSION "2" -class IPC : public QThread +class IPC : public QObject { Q_OBJECT IPC(); From 7cf1f564b071d5f046ca0bbbeca7d70ba1b65018 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 11 Oct 2015 23:07:37 +0200 Subject: [PATCH 3/6] remove dead code --- src/main.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b564c5425..6c6425142 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -233,15 +233,10 @@ int main(int argc, char *argv[]) } else if (!ipc.isCurrentOwner() && !parser.isSet("p")) { - uint32_t dest = 0; - if (parser.isSet("p")) - dest = Settings::getInstance().getCurrentProfileId(); - - time_t event = ipc.postEvent("activate", QByteArray(), dest); + time_t event = ipc.postEvent("activate"); if (ipc.waitUntilAccepted(event, 2)) { - if (!ipc.isCurrentOwner()) - return EXIT_SUCCESS; + return EXIT_SUCCESS; } } #endif From 6644622301e4a40b91057ab039d2aa26431ec7df Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 11 Oct 2015 23:08:49 +0200 Subject: [PATCH 4/6] fix #2360 The valid result prevents starting a second instance. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6c6425142..720d1bf37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) else if (!ipc.isCurrentOwner() && !parser.isSet("p")) { time_t event = ipc.postEvent("activate"); - if (ipc.waitUntilAccepted(event, 2)) + if (!ipc.waitUntilAccepted(event, 2)) { return EXIT_SUCCESS; } From 3f38ba389623bf53cdbe1100ede7d4ff41035b34 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sun, 11 Oct 2015 23:09:29 +0200 Subject: [PATCH 5/6] initialize IPC on first call --- src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 720d1bf37..3181e3683 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) parser.process(a); #ifndef Q_OS_ANDROID - IPC::getInstance(); + IPC& ipc = IPC::getInstance(); #endif sodium_init(); // For the auto-updater @@ -157,7 +157,6 @@ int main(int argc, char *argv[]) #ifndef Q_OS_ANDROID // Inter-process communication - IPC& ipc = IPC::getInstance(); ipc.registerEventHandler("uri", &toxURIEventHandler); ipc.registerEventHandler("save", &toxSaveEventHandler); ipc.registerEventHandler("activate", &toxActivateEventHandler); From a8725729bf73eb4cf7207e447ae3d49b38bb5fcc Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 12 Oct 2015 20:28:03 +0200 Subject: [PATCH 6/6] readd msleep with lowest possible sleep time --- src/ipc.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index 5197f7610..b8ab7cd6b 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -186,11 +186,13 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout/*=-1*/) { bool result = false; time_t start = time(0); - while (!(result = isEventAccepted(postTime))) - { - qApp->processEvents(); - if (timeout > 0 && difftime(time(0), start) >= timeout) + forever { + result = isEventAccepted(postTime); + if (result || (timeout > 0 && difftime(time(0), start) >= timeout)) break; + + qApp->processEvents(); + QThread::msleep(0); } return result; }