summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2019-07-07 13:44:26 +0200
committerGatis Paeglis <gatis.paeglis@qt.io>2019-07-08 13:23:39 +0200
commita41701904e880f58e19b352ade1931d6cd1a7112 (patch)
treecd4f92b54bd9c2daafe6042b2648de462d5fdf55 /src
parent1e9355fdf2c03e119c7e546c8bac3947d6c6b0b8 (diff)
xcb: fix thread synchronization issue in QXcbEventQueue::waitForNewEvents()
This patch amends 730cbad8824bcfcb7ab60371a6563cfb6dd5658d The issue was that the event reader thread (QXcbEventQueue::run()) can enqueue events sometime between GUI thread has last time peeked at the queue and before it has called waitForNewEvents() and hence started waiting for more events (via QWaitCondition). This scenario is even mentioned in the QWaitCondition documentation: "[..] if some of the threads are still in do_something() when the key is pressed, they won't be woken up (since they're not waiting on the condition variable) and so the task will not be performed for that key press. [..]" And if there are no more events on the X11 connection, the waitForNewEvents() in QXcbClipboard::waitForClipboardEvent() would timeout. Fixes: QTBUG-75319 Change-Id: I8990a2a0c00571dfc334fb57d616dee999042885 Reviewed-by: Igor Kushnir <igorkuo@gmail.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/xcb/qxcbeventqueue.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.cpp b/src/plugins/platforms/xcb/qxcbeventqueue.cpp
index acec0486c2..4ca73e3048 100644
--- a/src/plugins/platforms/xcb/qxcbeventqueue.cpp
+++ b/src/plugins/platforms/xcb/qxcbeventqueue.cpp
@@ -226,11 +226,13 @@ void QXcbEventQueue::run()
};
while (!m_closeConnectionDetected && (event = xcb_wait_for_event(connection))) {
+ m_newEventsMutex.lock();
enqueueEvent(event);
while (!m_closeConnectionDetected && (event = xcb_poll_for_queued_event(connection)))
enqueueEvent(event);
m_newEventsCondition.wakeOne();
+ m_newEventsMutex.unlock();
wakeUpDispatcher();
}
@@ -350,9 +352,12 @@ bool QXcbEventQueue::peekEventQueue(PeekerCallback peeker, void *peekerData,
void QXcbEventQueue::waitForNewEvents(unsigned long time)
{
- m_newEventsMutex.lock();
+ QMutexLocker locker(&m_newEventsMutex);
+ QXcbEventNode *tailBeforeFlush = m_flushedTail;
+ flushBufferedEvents();
+ if (tailBeforeFlush != m_flushedTail)
+ return;
m_newEventsCondition.wait(&m_newEventsMutex, time);
- m_newEventsMutex.unlock();
}
void QXcbEventQueue::sendCloseConnectionEvent() const