qtd3dservice: Lock the app to a single instance
authorAndrew Knight <andrew.knight@digia.com>
Thu, 13 Mar 2014 17:36:37 +0000 (19:36 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 15 Mar 2014 13:09:39 +0000 (14:09 +0100)
To avoid conflicts with multiple services running in tandem, create
a lock mutex and prevent starting multiple instances.

Change-Id: I0b1eede3947d8baafa309ffd8e214029a4b79bc5
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
src/qtd3dservice/d3dservice.cpp

index 06c0e9e..f8843c1 100644 (file)
@@ -189,6 +189,12 @@ static QString prepareCache(const QString &device, const QString &app)
 
 bool D3DService::start()
 {
+    HANDLE runLock = CreateMutex(NULL, TRUE, L"Local\\qtd3dservice");
+    if (!runLock || GetLastError() == ERROR_ALREADY_EXISTS) {
+        qCWarning(lcD3DService) << "The service is already running.";
+        return false;
+    }
+
     SetConsoleCtrlHandler(&control, TRUE);
 
     // Create an invisible window for getting broadcast events
@@ -400,6 +406,8 @@ bool D3DService::start()
             CloseHandle(waitHandles[i + 1]);
     }
 
+    CloseHandle(runLock);
+
     return true;
 }