From 524375bcdf8cf0caf3c6403e66d0e0af4b362c33 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Mon, 17 Feb 2014 10:10:24 +0200 Subject: [PATCH] CoreCon Server: guard with a QMutex The server may be used from several threads at once during startup, so use a mutex to protect initialization and enumeration of devices. Change-Id: I6a6605ac80af3da7f330474146e2256418892e50 Reviewed-by: Oliver Wolff --- src/shared/corecon/corecon.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/shared/corecon/corecon.cpp b/src/shared/corecon/corecon.cpp index c75f080..558e8b1 100644 --- a/src/shared/corecon/corecon.cpp +++ b/src/shared/corecon/corecon.cpp @@ -42,6 +42,8 @@ #include "corecon.h" #include +#include +#include #include #include @@ -133,10 +135,12 @@ public: ComPtr handle; QList devices; HMODULE langModule; + QMutex mutex; }; CoreConServer::CoreConServer() : d(new CoreConServerPrivate) { + QMutexLocker(&d->mutex); HRESULT hr = CoCreateInstance(CLSID_ConMan, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&d->handle)); if (FAILED(hr)) qCWarning(lcCoreCon) << "Failed to initialize connection server." << formatError(hr); @@ -158,6 +162,11 @@ QList CoreConServer::devices() const { qCDebug(lcCoreCon) << __FUNCTION__; + while (!d) + Sleep(1); + + QMutexLocker(&d->mutex); + if (!d->devices.isEmpty() || !d->handle) return d->devices; -- 2.7.4