summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2017-04-05 14:00:00 +0200
committerGatis Paeglis <gatis.paeglis@qt.io>2017-04-24 18:11:13 +0000
commitfbb485d4f6985643b27da3cc6c5b5f960c32e74d (patch)
tree7b9f3abae53c77718f3accad4776c56939b5ecae /src/platformsupport
parentc2cac34e94385e15e939f598386ae70a28e4408f (diff)
Prevent busy loop in glib event dispatcher
.. when running event loop with QEventLoop::ExcludeUserInputEvents. In a properly functioning code, g_main_context_iteration is expected to block until any event source becomes ready to dispatch an event (or interrupt occurs). Qt provides several custom event sources to the Glib event loop. The bug (busy loop) was caused by faulty event source implementation when QEventLoop::ExcludeUserInputEvents is set. As long as the window system's event queue was not empty, we signaled to the event dispatcher that there is an event ready to be dispatched. This results in the dispatcher calling the relevant dispatch function (which does handle the ExcludeUserInputEvents flag correctly). As we do not dispatch user events, the window system's event queue never becomes empty and we enter a busy loop (CPU running at 100%) where we signal that we have events to dispatch, but we actually do not dispatch them and g_main_context_iteration never gets to block. This busy loop can cause blocking GTK functions such as gtk_dialog_run() never return. Task-number: QTBUG-59760 Task-number: QTBUG-57101 Change-Id: I545b7951108eeaba019614ae8f5a1168c8b26c27 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Gunnar Sletta <gunnar@crimson.no>
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp b/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp
index 4c8a82470b..dc4785071f 100644
--- a/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp
+++ b/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp
@@ -46,8 +46,6 @@
#include <glib.h>
#include "private/qguiapplication_p.h"
-#include <qdebug.h>
-
QT_BEGIN_NAMESPACE
struct GUserEventSource
@@ -56,12 +54,15 @@ struct GUserEventSource
QPAEventDispatcherGlib *q;
};
-static gboolean userEventSourcePrepare(GSource *s, gint *timeout)
+static gboolean userEventSourcePrepare(GSource *source, gint *timeout)
{
- Q_UNUSED(s)
Q_UNUSED(timeout)
-
- return QWindowSystemInterface::windowSystemEventsQueued() > 0;
+ GUserEventSource *userEventSource = reinterpret_cast<GUserEventSource *>(source);
+ QPAEventDispatcherGlib *dispatcher = userEventSource->q;
+ if (dispatcher->m_flags & QEventLoop::ExcludeUserInputEvents)
+ return QWindowSystemInterface::nonUserInputEventsQueued();
+ else
+ return QWindowSystemInterface::windowSystemEventsQueued() > 0;
}
static gboolean userEventSourceCheck(GSource *source)