diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2018-09-19 11:14:10 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2018-10-16 06:56:47 +0000 |
commit | dd8a66daa497f0547f2fcddc0ee1e722d13ab98b (patch) | |
tree | b42401006509cc29833c40ec3561f1f0f95273f9 /src/plugins/platforms | |
parent | c89d0f9d532a2719118614b9fa9b8efffbe12f2f (diff) |
xcb: rework connection error handling
This patch reworks 0b1ce5db9e04b4c28713e87306fcea020c3e428b.
Just by looking at the source code it was unclear why is this
signal-and-slot connection necessary. It doesn't do anything on
normal exit - at the time we call dtor of this class,
QCoreApplication::instance() already is nullptr, which means that
no further event processing happens and we never get this signal.
Without digging into git history it may appear that the goal was
to process the remaining events on application exit, which would
be a questionable code by itself.
Change-Id: I202d11584901e3b52254d8e3c347aece17844b72
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbeventqueue.cpp | 27 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbeventqueue.h | 1 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.cpp b/src/plugins/platforms/xcb/qxcbeventqueue.cpp index 5bd4e7a68a..d7d70536a0 100644 --- a/src/plugins/platforms/xcb/qxcbeventqueue.cpp +++ b/src/plugins/platforms/xcb/qxcbeventqueue.cpp @@ -81,8 +81,6 @@ static bool dispatcherOwnerDestructing = false; QXcbEventQueue::QXcbEventQueue(QXcbConnection *connection) : m_connection(connection) { - connect(this, &QXcbEventQueue::finished, m_connection, &QXcbConnection::processXcbEvents); - // When running test cases in auto tests, static variables are preserved // between test function runs, even if Q*Application object is destroyed. // Reset to default value to account for this. @@ -199,14 +197,25 @@ void QXcbEventQueue::run() enqueueEvent(event); while (!m_closeConnectionDetected && (event = xcb_poll_for_queued_event(connection))) enqueueEvent(event); + wakeUpDispatcher(); + } - QMutexLocker locker(&qAppExiting); - if (!dispatcherOwnerDestructing) { - // This thread can run before a dispatcher has been created, - // so check if it is ready. - if (QCoreApplication::eventDispatcher()) - QCoreApplication::eventDispatcher()->wakeUp(); - } + if (!m_closeConnectionDetected) { + // Connection was terminated not by us. Wake up dispatcher, which will + // call processXcbEvents(), where we handle the connection errors via + // xcb_connection_has_error(). + wakeUpDispatcher(); + } +} + +void QXcbEventQueue::wakeUpDispatcher() +{ + QMutexLocker locker(&qAppExiting); + if (!dispatcherOwnerDestructing) { + // This thread can run before a dispatcher has been created, + // so check if it is ready. + if (QCoreApplication::eventDispatcher()) + QCoreApplication::eventDispatcher()->wakeUp(); } } diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.h b/src/plugins/platforms/xcb/qxcbeventqueue.h index bec2a6a201..0096437dba 100644 --- a/src/plugins/platforms/xcb/qxcbeventqueue.h +++ b/src/plugins/platforms/xcb/qxcbeventqueue.h @@ -83,6 +83,7 @@ public: bool isEmpty() const { return m_head == m_flushedTail && !m_head->event; } xcb_generic_event_t *takeFirst(); void flushBufferedEvents(); + void wakeUpDispatcher(); // ### peek() and peekEventQueue() could be unified. Note that peekEventQueue() // is public API exposed via QX11Extras/QX11Info. |