qt5: Fix timer leak in qtwayland to avoid animations being sluggish
[AGL/meta-agl.git] / meta-agl-core / dynamic-layers / meta-qt5 / recipes-qt / qt5 / qtwayland / 0001-Fix-timer-leak-and-a-potential-race.patch
1 From f4d3297e6705cc524729d629bf94db11841dbb24 Mon Sep 17 00:00:00 2001
2 From: Simon Yuan <simon.yuan@navico.com>
3 Date: Thu, 7 Nov 2019 09:22:37 +1300
4 Subject: [PATCH] Fix timer leak and a potential race
5
6 The callback timer is now killed immediately before starting a new timer, this
7 makes sure there is always a single active callback timer. It's unclear why
8 killing the timer in a separate lambda doesn't always kill the timer in time,
9 the hypothesis is that if killing the timer comes after starting a new one, then
10 the previous timer is now left dangling. Whatever the reason is, it makes even
11 more sense to kill the timer in the same lamda and immediately before starting a
12 new timer anyway.
13 ---
14  src/client/qwaylandwindow.cpp | 11 +++++------
15  1 file changed, 5 insertions(+), 6 deletions(-)
16
17 diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
18 index 0df99d9f..93b46bf1 100644
19 --- a/src/client/qwaylandwindow.cpp
20 +++ b/src/client/qwaylandwindow.cpp
21 @@ -1136,13 +1136,12 @@ void QWaylandWindow::handleUpdate()
22      mWaitingForFrameCallback = true;
23      mWaitingForUpdate = false;
24  
25 -    // Stop current frame timer if any, can't use killTimer directly, see comment above.
26 -    int fcbId = mFrameCallbackTimerId.fetchAndStoreOrdered(-1);
27 -    if (fcbId != -1)
28 -        QMetaObject::invokeMethod(this, [this, fcbId] { killTimer(fcbId); }, Qt::QueuedConnection);
29 -
30      // Start a timer for handling the case when the compositor stops sending frame callbacks.
31 -    QMetaObject::invokeMethod(this, [this] { // Again; can't do it directly
32 +    // Can't use killTimer directly, see comment above.
33 +    QMetaObject::invokeMethod(this, [this] {
34 +        int fcbId = mFrameCallbackTimerId.fetchAndStoreOrdered(-1);
35 +        if (fcbId != -1)
36 +            killTimer(fcbId);
37          if (mWaitingForFrameCallback)
38              mFrameCallbackTimerId = startTimer(100);
39      }, Qt::QueuedConnection);
40 -- 
41 2.25.1
42