summaryrefslogtreecommitdiff
blob: 74f5ed5c4886c3d2f0702c8ddd3c34d07b019e5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
From 0c0b34badb8a56f5c0d7d43c3847508774c8e553 Mon Sep 17 00:00:00 2001
From: Harald Sitter <sitter@kde.org>
Date: Mon, 2 Jan 2023 12:38:02 +0100
Subject: [PATCH] correctly set up ref counting in
 QThreadPool::tryStart(std::function)

this function was inconsistent with the QThreadPool::tryStart(QRunnable)
overload, where ref counting does get set up correctly. the lack of ref
counting setup would later cause trouble because we assert the ref
counting state all over QThreadPool. to prevent failed assertions we
correctly set up ref counting now.

this change is not applicable to Qt6 because the ref counting has
already been removed there:
https://github.com/qt/qtbase/commit/ecfda98d1f91c6a7da0d89826558d856cd88e670

BUG: 449688
---
 src/corelib/thread/qthreadpool.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index 40cc646519..8aa06a4c8f 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -602,8 +602,12 @@ bool QThreadPool::tryStart(std::function<void()> functionToRun)
         return false;
 
     QRunnable *runnable = QRunnable::create(std::move(functionToRun));
+    Q_ASSERT(runnable->ref == 0);
+    ++runnable->ref;
     if (d->tryStart(runnable))
         return true;
+    --runnable->ref;
+    Q_ASSERT(runnable->ref == 0);
     delete runnable;
     return false;
 }
-- 
GitLab