summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindowsysteminterface_p.h
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/gui/kernel/qwindowsysteminterface_p.h
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/gui/kernel/qwindowsysteminterface_p.h')
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 1bcc79552d..0f350fb2d2 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -458,6 +458,14 @@ public:
return impl.takeAt(i);
return 0;
}
+ bool nonUserInputEventsQueued()
+ {
+ const QMutexLocker locker(&mutex);
+ for (int i = 0; i < impl.size(); ++i)
+ if (!(impl.at(i)->type & QWindowSystemInterfacePrivate::UserInputEvent))
+ return true;
+ return false;
+ }
void append(WindowSystemEvent *e)
{ const QMutexLocker locker(&mutex); impl.append(e); }
int count() const
@@ -488,6 +496,7 @@ public:
static WindowSystemEventList windowSystemEventQueue;
static int windowSystemEventsQueued();
+ static bool nonUserInputEventsQueued();
static WindowSystemEvent *getWindowSystemEvent();
static WindowSystemEvent *getNonUserInputWindowSystemEvent();
static WindowSystemEvent *peekWindowSystemEvent(EventType t);