summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2023-01-02 14:19:02 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2023-01-03 11:21:15 +0100
commit69ea84fd71d66e095a4d3f581f276fe5b41964a3 (patch)
tree43d96a32c106b6b9c5b01147696948d297260615
parent470587e7ca9a0c7886c820e2bf20fbded976b16f (diff)
Fix the ref-counting for the std::function version of tryStart()
The refcount isn't used, but is asserted in debug mode. Fixes: QTBUG-109732 Change-Id: I5c4f402ca2a15b92f318896de994f3bfedf4eb87 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/thread/qthreadpool.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index 7eb1e1fbce..a627b0fb50 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;
}