summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qeventdispatcher_win.cpp
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@theqtcompany.com>2014-11-07 11:04:49 +0200
committerAndrew Knight <andrew.knight@theqtcompany.com>2014-11-07 14:54:08 +0100
commit3d70925ee54d06e90bea392883d230b8ae2b1782 (patch)
tree2d7a3b576620542bea62c198e54ece079d24d624 /src/corelib/kernel/qeventdispatcher_win.cpp
parent21e5d77e85ced10db6fe9c1bf2e0461195e1560c (diff)
direct2d: Use simple event posting to avoid event queue lock up
In rare cases, the Windows event loop can be spinning inside the inner loop and the message hook is never called. This can be triggered on the Direct2D platform by opening 32+ window handles. The issue can be worked around by using the same approach Windows CE uses: don't rely on the message hook to inform the event loop that the post message has been delivered. Instead, uninstall the hook and let it be called directly by the event loop. Task-number: QTBUG-42428 Change-Id: I10280126dd50729bc260aa5f7029549e2e061c01 Reviewed-by: Louai Al-Khanji <louai.al-khanji@theqtcompany.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src/corelib/kernel/qeventdispatcher_win.cpp')
-rw-r--r--src/corelib/kernel/qeventdispatcher_win.cpp57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp
index a3d00faf31..62e6e9f051 100644
--- a/src/corelib/kernel/qeventdispatcher_win.cpp
+++ b/src/corelib/kernel/qeventdispatcher_win.cpp
@@ -434,9 +434,10 @@ static inline UINT inputTimerMask()
LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp)
{
+ QEventDispatcherWin32 *q = qobject_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance());
+ Q_ASSERT(q != 0);
+
if (wp == PM_REMOVE) {
- QEventDispatcherWin32 *q = qobject_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance());
- Q_ASSERT(q != 0);
if (q) {
MSG *msg = (MSG *) lp;
QEventDispatcherWin32Private *d = q->d_func();
@@ -472,7 +473,7 @@ LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp)
#ifdef Q_OS_WINCE
return 0;
#else
- return CallNextHookEx(0, code, wp, lp);
+ return q->d_func()->getMessageHook ? CallNextHookEx(0, code, wp, lp) : 0;
#endif
}
@@ -643,15 +644,7 @@ void QEventDispatcherWin32::createInternalHwnd()
return;
d->internalHwnd = qt_create_internal_window(this);
-#ifndef Q_OS_WINCE
- // setup GetMessage hook needed to drive our posted events
- d->getMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) qt_GetMessageHook, NULL, GetCurrentThreadId());
- if (!d->getMessageHook) {
- int errorCode = GetLastError();
- qFatal("Qt: INTERNAL ERROR: failed to install GetMessage hook: %d, %s",
- errorCode, qPrintable(qt_error_string(errorCode)));
- }
-#endif
+ installMessageHook();
// register all socket notifiers
QList<int> sockets = (d->sn_read.keys().toSet()
@@ -665,6 +658,35 @@ void QEventDispatcherWin32::createInternalHwnd()
d->registerTimer(d->timerVec.at(i));
}
+void QEventDispatcherWin32::installMessageHook()
+{
+ Q_D(QEventDispatcherWin32);
+
+ if (d->getMessageHook)
+ return;
+
+#ifndef Q_OS_WINCE
+ // setup GetMessage hook needed to drive our posted events
+ d->getMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) qt_GetMessageHook, NULL, GetCurrentThreadId());
+ if (!d->getMessageHook) {
+ int errorCode = GetLastError();
+ qFatal("Qt: INTERNAL ERROR: failed to install GetMessage hook: %d, %s",
+ errorCode, qPrintable(qt_error_string(errorCode)));
+ }
+#endif
+}
+
+void QEventDispatcherWin32::uninstallMessageHook()
+{
+ Q_D(QEventDispatcherWin32);
+
+#ifndef Q_OS_WINCE
+ if (d->getMessageHook)
+ UnhookWindowsHookEx(d->getMessageHook);
+#endif
+ d->getMessageHook = 0;
+}
+
QEventDispatcherWin32::QEventDispatcherWin32(QObject *parent)
: QAbstractEventDispatcher(*new QEventDispatcherWin32Private, parent)
{
@@ -750,10 +772,9 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
}
}
if (haveMessage) {
-#ifdef Q_OS_WINCE
// WinCE doesn't support hooks at all, so we have to call this by hand :(
- (void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM) &msg);
-#endif
+ if (!d->getMessageHook)
+ (void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM) &msg);
if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) {
if (seenWM_QT_SENDPOSTEDEVENTS) {
@@ -1134,11 +1155,7 @@ void QEventDispatcherWin32::closingDown()
d->timerVec.clear();
d->timerDict.clear();
-#ifndef Q_OS_WINCE
- if (d->getMessageHook)
- UnhookWindowsHookEx(d->getMessageHook);
- d->getMessageHook = 0;
-#endif
+ uninstallMessageHook();
}
bool QEventDispatcherWin32::event(QEvent *e)