From b41a7e47ee42060c7a5ab805d368f7ba15e5c742 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 15 Mar 2022 16:53:04 +0100 Subject: [PATCH] Fix race condition on mWaitingForUpdateDelivery Change-Id: I0e91bda73722468b9339fc434fe04420b5e7d3da Reviewed-by: David Edmundson --- src/plugins/platforms/wayland/qwaylandwindow.cpp | 6 ++---- src/plugins/platforms/wayland/qwaylandwindow_p.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 05e7160be23..23e7366088e 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -716,18 +716,17 @@ void QWaylandWindow::handleFrameCallback() mFrameCallbackElapsedTimer.invalidate(); // The rest can wait until we can run it on the correct thread - if (!mWaitingForUpdateDelivery) { + if (mWaitingForUpdateDelivery.testAndSetAcquire(false, true)) { // Queued connection, to make sure we don't call handleUpdate() from inside waitForFrameSync() // in the single-threaded case. - mWaitingForUpdateDelivery = true; QMetaObject::invokeMethod(this, &QWaylandWindow::doHandleFrameCallback, Qt::QueuedConnection); } - mFrameSyncWait.notify_all(); } void QWaylandWindow::doHandleFrameCallback() { + mWaitingForUpdateDelivery.storeRelease(false); bool wasExposed = isExposed(); mFrameCallbackTimedOut = false; if (!wasExposed && isExposed()) // Did setting mFrameCallbackTimedOut make the window exposed? @@ -735,7 +734,6 @@ void QWaylandWindow::doHandleFrameCallback() if (wasExposed && hasPendingUpdateRequest()) deliverUpdateRequest(); - mWaitingForUpdateDelivery = false; } bool QWaylandWindow::waitForFrameSync(int timeout) diff --git a/src/plugins/platforms/wayland/qwaylandwindow_p.h b/src/plugins/platforms/wayland/qwaylandwindow_p.h index d8eebb738aa..8fcbc4dccb6 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow_p.h +++ b/src/plugins/platforms/wayland/qwaylandwindow_p.h @@ -283,7 +283,7 @@ protected: WId mWindowId; bool mWaitingForFrameCallback = false; bool mFrameCallbackTimedOut = false; // Whether the frame callback has timed out - bool mWaitingForUpdateDelivery = false; + QAtomicInt mWaitingForUpdateDelivery = false; int mFrameCallbackCheckIntervalTimerId = -1; QElapsedTimer mFrameCallbackElapsedTimer; struct ::wl_callback *mFrameCallback = nullptr;