From 2be0bf0765aae2d8c7ec794241733b170d61c981 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Tue, 12 Aug 2014 14:33:58 +0300 Subject: winrt: Fix deadlock in thread dispatcher access An event dispatcher fetching the core dispatcher can deadlock when looking up the window. Simplify this by only looking up the view, and treating the event dispatcher as one which will never obtain the core dispatcher. This fixes a deadlock which occurs when starting network delegates. Change-Id: Ic27f4ab6f168eb95f3de70d78d64f035c331a7f5 Reviewed-by: Oliver Wolff --- src/corelib/kernel/qeventdispatcher_winrt.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index c8f959a962..aec0981677 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -148,12 +148,14 @@ private: hr = application->get_MainView(&view); RETURN_VOID_IF_FAILED("Failed to get the main view"); - ComPtr window; - hr = view->get_CoreWindow(&window); - RETURN_VOID_IF_FAILED("Failed to get the core window"); + ComPtr view2; + hr = view.As(&view2); + RETURN_VOID_IF_FAILED("Failed to cast the main view"); - hr = window->get_Dispatcher(&coreDispatcher); - RETURN_VOID_IF_FAILED("Failed to get the core dispatcher"); + hr = view2->get_Dispatcher(&coreDispatcher); + if (hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) // expected in thread pool cases + return; + RETURN_VOID_IF_FAILED("Failed to get core dispatcher"); thread = QThread::currentThread(); } @@ -186,7 +188,7 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherWinRT); - if (d->thread != QThread::currentThread()) + if (d->thread && d->thread != QThread::currentThread()) d->fetchCoreDispatcher(); bool didProcess = false; -- cgit v1.2.3