diff options
author | Andrew Knight <andrew.knight@digia.com> | 2014-03-13 19:36:37 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-15 14:09:39 +0100 |
commit | 34c8f1a20e0593723785988c98a1858e40891614 (patch) | |
tree | e097ad7b5fb23005b3648d3e65e31d96f0fe902f | |
parent | 2c9f0207a7e001c13281015f047fca667e4b7e14 (diff) | |
download | qttools-34c8f1a20e0593723785988c98a1858e40891614.tar.gz |
qtd3dservice: Lock the app to a single instance
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>
-rw-r--r-- | src/qtd3dservice/d3dservice.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/qtd3dservice/d3dservice.cpp b/src/qtd3dservice/d3dservice.cpp index 06c0e9ec9..f8843c1a0 100644 --- a/src/qtd3dservice/d3dservice.cpp +++ b/src/qtd3dservice/d3dservice.cpp @@ -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; } |