summaryrefslogtreecommitdiffstats
path: root/src/concurrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/concurrent')
-rw-r--r--src/concurrent/CMakeLists.txt6
-rw-r--r--src/concurrent/doc/qtconcurrent.qdocconf9
-rw-r--r--src/concurrent/doc/snippets/CMakeLists.txt3
-rw-r--r--src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp2
-rw-r--r--src/concurrent/doc/src/qt6-changes.qdoc2
-rw-r--r--src/concurrent/doc/src/qtconcurrent-examples.qdoc14
-rw-r--r--src/concurrent/doc/src/qtconcurrent-index.qdoc6
-rw-r--r--src/concurrent/qtaskbuilder.h6
-rw-r--r--src/concurrent/qtaskbuilder.qdoc2
-rw-r--r--src/concurrent/qtconcurrentfilter.cpp1
-rw-r--r--src/concurrent/qtconcurrentfilter.h30
-rw-r--r--src/concurrent/qtconcurrentfilterkernel.h2
-rw-r--r--src/concurrent/qtconcurrentfunctionwrappers.h2
-rw-r--r--src/concurrent/qtconcurrentiteratekernel.cpp4
-rw-r--r--src/concurrent/qtconcurrentiteratekernel.h12
-rw-r--r--src/concurrent/qtconcurrentmap.cpp1
-rw-r--r--src/concurrent/qtconcurrentmap.h38
-rw-r--r--src/concurrent/qtconcurrentmapkernel.h2
-rw-r--r--src/concurrent/qtconcurrentmedian.h2
-rw-r--r--src/concurrent/qtconcurrentreducekernel.h10
-rw-r--r--src/concurrent/qtconcurrentrun.cpp16
-rw-r--r--src/concurrent/qtconcurrentrun.h25
-rw-r--r--src/concurrent/qtconcurrenttask.h4
-rw-r--r--src/concurrent/qtconcurrenttask.qdoc1
-rw-r--r--src/concurrent/qtconcurrentthreadengine.cpp6
-rw-r--r--src/concurrent/qtconcurrentthreadengine.h2
26 files changed, 133 insertions, 75 deletions
diff --git a/src/concurrent/CMakeLists.txt b/src/concurrent/CMakeLists.txt
index bc353f4e89..504f854534 100644
--- a/src/concurrent/CMakeLists.txt
+++ b/src/concurrent/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from concurrent.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## Concurrent Module:
@@ -24,8 +25,10 @@ qt_internal_add_module(Concurrent
qtconcurrenttask.h
qtconcurrentthreadengine.cpp qtconcurrentthreadengine.h
DEFINES
+ QT_NO_CONTEXTLESS_CONNECT
QT_NO_FOREACH
QT_NO_USING_NAMESPACE
+ QT_USE_NODISCARD_FILE_OPEN
LIBRARIES
Qt::CorePrivate
PUBLIC_LIBRARIES
@@ -47,4 +50,3 @@ qt_internal_extend_target(Concurrent CONDITION MSVC AND (TEST_architecture_arch
qt_internal_add_docs(Concurrent
doc/qtconcurrent.qdocconf
)
-
diff --git a/src/concurrent/doc/qtconcurrent.qdocconf b/src/concurrent/doc/qtconcurrent.qdocconf
index 9e8b280f0b..c4efe64d0a 100644
--- a/src/concurrent/doc/qtconcurrent.qdocconf
+++ b/src/concurrent/doc/qtconcurrent.qdocconf
@@ -15,15 +15,18 @@ qhp.QtConcurrent.virtualFolder = qtconcurrent
qhp.QtConcurrent.indexTitle = Qt Concurrent
qhp.QtConcurrent.indexRoot =
-qhp.QtConcurrent.subprojects = classes
+qhp.QtConcurrent.subprojects = classes examples
qhp.QtConcurrent.subprojects.classes.title = C++ Classes
qhp.QtConcurrent.subprojects.classes.indexTitle = Qt Concurrent C++ Classes
qhp.QtConcurrent.subprojects.classes.selectors = class fake:headerfile
qhp.QtConcurrent.subprojects.classes.sortPages = true
+qhp.QtConcurrent.subprojects.examples.title = Qt Concurrent Examples
+qhp.QtConcurrent.subprojects.examples.indexTitle = Qt Concurrent Examples
+qhp.QtConcurrent.subprojects.examples.selectors = fake:example
tagfile = ../../../doc/qtconcurrent/qtconcurrent.tags
-depends += qtcore qtdoc qmake qtcmake
+depends += qtcore qtnetwork qtdoc qmake qtcmake
headerdirs += ..
@@ -40,5 +43,5 @@ imagedirs += images
navigation.landingpage = "Qt Concurrent"
navigation.cppclassespage = "Qt Concurrent C++ Classes"
-# Fail the documentation build if there are more warnings than the limit
+# Enforce zero documentation warnings
warninglimit = 0
diff --git a/src/concurrent/doc/snippets/CMakeLists.txt b/src/concurrent/doc/snippets/CMakeLists.txt
index 1b0879a79f..03ebb75a2e 100644
--- a/src/concurrent/doc/snippets/CMakeLists.txt
+++ b/src/concurrent/doc/snippets/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
#! [cmake_use]
find_package(Qt6 REQUIRED COMPONENTS Concurrent)
target_link_libraries(mytarget PRIVATE Qt6::Concurrent)
diff --git a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp
index ac3ca7fdfb..cb1889afb6 100644
--- a/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp
+++ b/src/concurrent/doc/snippets/code/src_concurrent_qtconcurrenttask.cpp
@@ -30,7 +30,7 @@ std::is_invocable_v<std::decay_t<Task>, std::decay_t<Args>...>
//! [5]
QVariant value(42);
-auto result = QtConcurrent::task(&qvariant_cast<int>)
+auto result = QtConcurrent::task([](const QVariant &var){return qvariant_cast<int>(var);})
.withArguments(value)
.spawn()
.result(); // result == 42
diff --git a/src/concurrent/doc/src/qt6-changes.qdoc b/src/concurrent/doc/src/qt6-changes.qdoc
index cb0c606435..fa23ee21a7 100644
--- a/src/concurrent/doc/src/qt6-changes.qdoc
+++ b/src/concurrent/doc/src/qt6-changes.qdoc
@@ -5,7 +5,7 @@
\page concurrent-changes-qt6.html
\title Changes to Qt Concurrent
\ingroup changes-qt-5-to-6
- \brief Migrate Qt Concurrent to Qt 6.
+ \brief Improved to work with a variable number of arguments.
Qt 6 is a result of the conscious effort to make the framework more
efficient and easy to use.
diff --git a/src/concurrent/doc/src/qtconcurrent-examples.qdoc b/src/concurrent/doc/src/qtconcurrent-examples.qdoc
new file mode 100644
index 0000000000..06705cca1b
--- /dev/null
+++ b/src/concurrent/doc/src/qtconcurrent-examples.qdoc
@@ -0,0 +1,14 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \group qtconcurrentexamples
+ \title Qt Concurrent Examples
+ \brief Examples for the Qt Concurrent module
+ \ingroup all-examples
+ \ingroup qtconcurrent
+
+ The list of \l {Qt Concurrent} examples demonstrating how to use
+ Qt Concurrent API from C++.
+
+*/
diff --git a/src/concurrent/doc/src/qtconcurrent-index.qdoc b/src/concurrent/doc/src/qtconcurrent-index.qdoc
index 368f94fb69..5acf19e134 100644
--- a/src/concurrent/doc/src/qtconcurrent-index.qdoc
+++ b/src/concurrent/doc/src/qtconcurrent-index.qdoc
@@ -130,6 +130,12 @@
\include module-use.qdocinc building with qmake
\snippet snippets/snippets.pro qmake_use
+ \section1 Examples
+
+ \list
+ \li \l {Qt Concurrent Examples}
+ \endlist
+
\section1 Module Evolution
\l{Changes to Qt Concurrent} lists important changes in the module API
and functionality that were done for the Qt 6 series of Qt.
diff --git a/src/concurrent/qtaskbuilder.h b/src/concurrent/qtaskbuilder.h
index 2f4a39b9e9..95ab8021e7 100644
--- a/src/concurrent/qtaskbuilder.h
+++ b/src/concurrent/qtaskbuilder.h
@@ -4,13 +4,13 @@
#ifndef QTBASE_QTTASKBUILDER_H
#define QTBASE_QTTASKBUILDER_H
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
QT_BEGIN_NAMESPACE
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
namespace QtConcurrent {
@@ -126,7 +126,7 @@ private: // Data
} // namespace QtConcurrent
-#endif // Q_CLANG_QDOC
+#endif // Q_QDOC
QT_END_NAMESPACE
diff --git a/src/concurrent/qtaskbuilder.qdoc b/src/concurrent/qtaskbuilder.qdoc
index 19c117b156..811a48f62b 100644
--- a/src/concurrent/qtaskbuilder.qdoc
+++ b/src/concurrent/qtaskbuilder.qdoc
@@ -51,7 +51,7 @@
*/
/*!
- \typedef InvokeResultType
+ \typedef QtConcurrent::InvokeResultType
\relates QtConcurrent::QTaskBuilder
The simplified definition of this type looks like this:
diff --git a/src/concurrent/qtconcurrentfilter.cpp b/src/concurrent/qtconcurrentfilter.cpp
index 0f8b6ae4f8..35141d2d7e 100644
--- a/src/concurrent/qtconcurrentfilter.cpp
+++ b/src/concurrent/qtconcurrentfilter.cpp
@@ -4,6 +4,7 @@
/*!
\page qtconcurrentfilter.html
\title Concurrent Filter and Filter-Reduce
+ \brief Selecting values from a sequence and combining them, all in parallel.
\ingroup thread
The QtConcurrent::filter(), QtConcurrent::filtered() and
diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h
index e35c445b94..d9fbc1b019 100644
--- a/src/concurrent/qtconcurrentfilter.h
+++ b/src/concurrent/qtconcurrentfilter.h
@@ -4,9 +4,13 @@
#ifndef QTCONCURRENT_FILTER_H
#define QTCONCURRENT_FILTER_H
+#if 0
+#pragma qt_class(QtConcurrentFilter)
+#endif
+
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <QtConcurrent/qtconcurrentfilterkernel.h>
#include <QtConcurrent/qtconcurrentfunctionwrappers.h>
@@ -67,7 +71,7 @@ QFuture<ResultType> filteredReduced(Sequence &&sequence,
std::forward<KeepFunctor>(keep), std::forward<ReduceFunctor>(reduce), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -90,7 +94,7 @@ QFuture<ResultType> filteredReduced(QThreadPool *pool,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -112,7 +116,7 @@ QFuture<ResultType> filteredReduced(Sequence &&sequence,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
@@ -209,7 +213,7 @@ QFuture<ResultType> filteredReduced(Iterator begin,
std::forward<ReduceFunctor>(reduce), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -232,7 +236,7 @@ QFuture<ResultType> filteredReduced(QThreadPool *pool,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -255,7 +259,7 @@ QFuture<ResultType> filteredReduced(Iterator begin,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
QFuture<ResultType> filteredReduced(QThreadPool *pool,
@@ -402,7 +406,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -426,7 +430,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -449,7 +453,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence,
return future.takeResult();
}
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
std::enable_if_t<QtPrivate::isInvocable<KeepFunctor, Sequence>::value, int> = 0,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
@@ -553,7 +557,7 @@ ResultType blockingFilteredReduced(Iterator begin,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -577,7 +581,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -600,7 +604,7 @@ ResultType blockingFilteredReduced(Iterator begin,
return future.takeResult();
}
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultTypeHelper<ReduceFunctor>::type>
ResultType blockingFilteredReduced(QThreadPool *pool,
diff --git a/src/concurrent/qtconcurrentfilterkernel.h b/src/concurrent/qtconcurrentfilterkernel.h
index b05508d024..68664c7f52 100644
--- a/src/concurrent/qtconcurrentfilterkernel.h
+++ b/src/concurrent/qtconcurrentfilterkernel.h
@@ -6,7 +6,7 @@
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined (Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined (Q_QDOC)
#include <QtConcurrent/qtconcurrentiteratekernel.h>
#include <QtConcurrent/qtconcurrentmapkernel.h>
diff --git a/src/concurrent/qtconcurrentfunctionwrappers.h b/src/concurrent/qtconcurrentfunctionwrappers.h
index 4882ed8d89..78900c239b 100644
--- a/src/concurrent/qtconcurrentfunctionwrappers.h
+++ b/src/concurrent/qtconcurrentfunctionwrappers.h
@@ -10,7 +10,7 @@
#include <tuple>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
QT_BEGIN_NAMESPACE
diff --git a/src/concurrent/qtconcurrentiteratekernel.cpp b/src/concurrent/qtconcurrentiteratekernel.cpp
index b735ae4137..00228f181c 100644
--- a/src/concurrent/qtconcurrentiteratekernel.cpp
+++ b/src/concurrent/qtconcurrentiteratekernel.cpp
@@ -7,7 +7,7 @@
#include "private/qfunctions_p.h"
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
QT_BEGIN_NAMESPACE
@@ -67,7 +67,7 @@ namespace QtConcurrent {
*/
BlockSizeManager::BlockSizeManager(QThreadPool *pool, int iterationCount)
- : maxBlockSize(iterationCount / (pool->maxThreadCount() * 2)),
+ : maxBlockSize(iterationCount / (std::max(pool->maxThreadCount(), 1) * 2)),
beforeUser(0), afterUser(0),
m_blockSize(1)
{ }
diff --git a/src/concurrent/qtconcurrentiteratekernel.h b/src/concurrent/qtconcurrentiteratekernel.h
index 86150f1d97..232f4c8bfe 100644
--- a/src/concurrent/qtconcurrentiteratekernel.h
+++ b/src/concurrent/qtconcurrentiteratekernel.h
@@ -6,7 +6,7 @@
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <QtCore/qatomic.h>
#include <QtConcurrent/qtconcurrentmedian.h>
@@ -65,7 +65,7 @@ public:
void reserveSpace(int resultCount)
{
currentResultCount = resultCount;
- resizeList(qMax(resultCount, vector.count()));
+ resizeList(qMax(resultCount, vector.size()));
}
void reportResults(int begin)
@@ -85,7 +85,7 @@ public:
return vector.data();
}
- int currentResultCount;
+ int currentResultCount = 0;
ThreadEngine<T> *threadEngine;
QList<T> vector;
@@ -156,7 +156,7 @@ public:
begin(_begin),
end(_end),
current(_begin),
- iterationCount(selectIteration(IteratorCategory()) ? std::distance(_begin, _end) : 0),
+ iterationCount(selectIteration(IteratorCategory()) ? static_cast<int>(std::distance(_begin, _end)) : 0),
forIteration(selectIteration(IteratorCategory())),
progressReportingEnabled(true)
{
@@ -168,7 +168,7 @@ public:
begin(_begin),
end(_end),
current(_begin),
- iterationCount(selectIteration(IteratorCategory()) ? std::distance(_begin, _end) : 0),
+ iterationCount(selectIteration(IteratorCategory()) ? static_cast<int>(std::distance(_begin, _end)) : 0),
forIteration(selectIteration(IteratorCategory())),
progressReportingEnabled(true),
defaultValue(U())
@@ -181,7 +181,7 @@ public:
begin(_begin),
end(_end),
current(_begin),
- iterationCount(selectIteration(IteratorCategory()) ? std::distance(_begin, _end) : 0),
+ iterationCount(selectIteration(IteratorCategory()) ? static_cast<int>(std::distance(_begin, _end)) : 0),
forIteration(selectIteration(IteratorCategory())),
progressReportingEnabled(true),
defaultValue(std::forward<U>(_defaultValue))
diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp
index ea805b44df..222c8cd639 100644
--- a/src/concurrent/qtconcurrentmap.cpp
+++ b/src/concurrent/qtconcurrentmap.cpp
@@ -108,6 +108,7 @@
/*!
\page qtconcurrentmap.html
\title Concurrent Map and Map-Reduce
+ \brief Transforming values from a sequence and combining them, all in parallel.
\ingroup thread
The QtConcurrent::map(), QtConcurrent::mapped() and
diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h
index 2d829daca4..bd959f44d3 100644
--- a/src/concurrent/qtconcurrentmap.h
+++ b/src/concurrent/qtconcurrentmap.h
@@ -4,9 +4,13 @@
#ifndef QTCONCURRENT_MAP_H
#define QTCONCURRENT_MAP_H
+#if 0
+#pragma qt_class(QtConcurrentMap)
+#endif
+
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <QtConcurrent/qtconcurrentmapkernel.h>
#include <QtConcurrent/qtconcurrentreducekernel.h>
@@ -71,7 +75,7 @@ QFuture<ResultType> mappedReduced(Sequence &&sequence,
std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -93,7 +97,7 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
std::forward<ReduceFunctor>(reduce),
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -144,7 +148,7 @@ QFuture<ResultType> mappedReduced(Sequence &&sequence,
std::forward<MapFunctor>(map), std::forward<ReduceFunctor>(reduce), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
@@ -168,7 +172,7 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename Sequence, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
@@ -219,7 +223,7 @@ QFuture<ResultType> mappedReduced(Iterator begin,
std::forward<ReduceFunctor>(reduce), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -242,7 +246,7 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -294,7 +298,7 @@ QFuture<ResultType> mappedReduced(Iterator begin,
std::forward<ReduceFunctor>(reduce), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
@@ -318,7 +322,7 @@ QFuture<ResultType> mappedReduced(QThreadPool *pool,
ResultType(std::forward<InitialValueType>(initialValue)), options);
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
@@ -449,7 +453,7 @@ ResultType blockingMappedReduced(Sequence &&sequence,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -473,7 +477,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -529,7 +533,7 @@ ResultType blockingMappedReduced(Sequence &&sequence,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType,
typename InitialValueType>
#else
@@ -554,7 +558,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename MapFunctor, typename ReduceFunctor, typename Sequence, typename ResultType,
typename InitialValueType>
#else
@@ -608,7 +612,7 @@ ResultType blockingMappedReduced(Iterator begin,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -633,7 +637,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType>
#else
@@ -688,7 +692,7 @@ ResultType blockingMappedReduced(Iterator begin,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
@@ -713,7 +717,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
return future.takeResult();
}
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
template <typename Iterator, typename MapFunctor, typename ReduceFunctor, typename ResultType,
typename InitialValueType>
#else
diff --git a/src/concurrent/qtconcurrentmapkernel.h b/src/concurrent/qtconcurrentmapkernel.h
index 763a8c2d03..61b18e5438 100644
--- a/src/concurrent/qtconcurrentmapkernel.h
+++ b/src/concurrent/qtconcurrentmapkernel.h
@@ -6,7 +6,7 @@
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined (Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined (Q_QDOC)
#include <QtConcurrent/qtconcurrentiteratekernel.h>
#include <QtConcurrent/qtconcurrentreducekernel.h>
diff --git a/src/concurrent/qtconcurrentmedian.h b/src/concurrent/qtconcurrentmedian.h
index a4896bb72c..01cb8b93e0 100644
--- a/src/concurrent/qtconcurrentmedian.h
+++ b/src/concurrent/qtconcurrentmedian.h
@@ -6,7 +6,7 @@
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <algorithm>
#include <cstring>
diff --git a/src/concurrent/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h
index a58739fc41..c337a9192f 100644
--- a/src/concurrent/qtconcurrentreducekernel.h
+++ b/src/concurrent/qtconcurrentreducekernel.h
@@ -6,7 +6,7 @@
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <QtCore/qatomic.h>
#include <QtCore/qlist.h>
@@ -40,7 +40,7 @@ namespace QtConcurrent {
MapReduce won't start any new threads, and when it exceeds
ReduceQueueThrottleLimit running threads will be stopped.
*/
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
enum ReduceQueueLimits {
ReduceQueueStartLimit = 20,
ReduceQueueThrottleLimit = 30
@@ -70,7 +70,7 @@ enum ReduceOption {
// ParallelReduce = 0x8
};
Q_DECLARE_FLAGS(ReduceOptions, ReduceOption)
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
Q_DECLARE_OPERATORS_FOR_FLAGS(ReduceOptions)
#endif
// supports both ordered and out-of-order reduction
@@ -117,7 +117,7 @@ class ReduceKernel
public:
ReduceKernel(QThreadPool *pool, ReduceOptions _reduceOptions)
: reduceOptions(_reduceOptions), progress(0), resultsMapSize(0),
- threadCount(pool->maxThreadCount())
+ threadCount(std::max(pool->maxThreadCount(), 1))
{ }
void runReduce(ReduceFunctor &reduce,
@@ -187,11 +187,13 @@ public:
inline bool shouldThrottle()
{
+ std::lock_guard<QMutex> locker(mutex);
return (resultsMapSize > (ReduceQueueThrottleLimit * threadCount));
}
inline bool shouldStartThread()
{
+ std::lock_guard<QMutex> locker(mutex);
return (resultsMapSize <= (ReduceQueueStartLimit * threadCount));
}
};
diff --git a/src/concurrent/qtconcurrentrun.cpp b/src/concurrent/qtconcurrentrun.cpp
index b0872b0c01..017f2df480 100644
--- a/src/concurrent/qtconcurrentrun.cpp
+++ b/src/concurrent/qtconcurrentrun.cpp
@@ -4,6 +4,7 @@
/*!
\page qtconcurrentrun.html
\title Concurrent Run
+ \brief A simple way to run a task in a separate thread.
\ingroup thread
The QtConcurrent::run() function runs a function in a separate thread.
@@ -79,6 +80,10 @@
\snippet code/src_concurrent_qtconcurrentrun.cpp 2
+ If you don't need the result (for example, because the function returns
+ \c{void}), using the QThreadPool::start() overload taking a function object
+ is more efficient.
+
As documented above, passing arguments is done like this:
\snippet code/src_concurrent_qtconcurrentrun.cpp 3
@@ -219,7 +224,7 @@
*/
/*!
- \fn QFuture<T> QtConcurrent::run(Function function, ...);
+ \fn template <typename T> QFuture<T> QtConcurrent::run(Function function, ...);
Equivalent to
\code
@@ -250,17 +255,16 @@
running task, fetching multiple results from the called \a function or
monitoring progress reported by the \a function.
- \sa {Concurrent Run (basic mode)}, {Concurrent Run With Promise}
+ \sa {Concurrent Run (basic mode)}, {Concurrent Run With Promise}, QThreadPool::start()
//! [run-description]
*/
/*!
\since 5.4
- \fn QFuture<T> QtConcurrent::run(QThreadPool *pool, Function function, ...);
+ \fn template <typename T> QFuture<T> QtConcurrent::run(QThreadPool *pool, Function function, ...);
- Runs \a function in a separate thread. The thread is taken from the
- QThreadPool \a pool. Note that \a function may not run immediately; \a function
- will only be run once a thread becomes available.
+ Schedules \a function on \a pool. Note that \a function may not run
+ immediately; \a function will only be run once a thread becomes available.
\include qtconcurrentrun.cpp run-description
*/
diff --git a/src/concurrent/qtconcurrentrun.h b/src/concurrent/qtconcurrentrun.h
index fdcebe0bde..cbc750de84 100644
--- a/src/concurrent/qtconcurrentrun.h
+++ b/src/concurrent/qtconcurrentrun.h
@@ -4,16 +4,20 @@
#ifndef QTCONCURRENT_RUN_H
#define QTCONCURRENT_RUN_H
+#if 0
+#pragma qt_class(QtConcurrentRun)
+#endif
+
#include <QtConcurrent/qtconcurrentcompilertest.h>
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
#include <QtConcurrent/qtconcurrentrunbase.h>
#include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
QT_BEGIN_NAMESPACE
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
typedef int Function;
@@ -31,8 +35,11 @@ namespace QtConcurrent {
namespace QtConcurrent {
+#define QTCONCURRENT_RUN_NODISCARD \
+ Q_NODISCARD_X("Use QThreadPool::start(Callable&&) if you don't need the returned QFuture")
+
template <class Function, class ...Args>
-[[nodiscard]]
+QTCONCURRENT_RUN_NODISCARD
auto run(QThreadPool *pool, Function &&f, Args &&...args)
{
DecayedTuple<Function, Args...> tuple { std::forward<Function>(f),
@@ -42,7 +49,7 @@ auto run(QThreadPool *pool, Function &&f, Args &&...args)
}
template <class Function, class ...Args>
-[[nodiscard]]
+QTCONCURRENT_RUN_NODISCARD
auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWrapper,
Args &&...args)
{
@@ -51,7 +58,7 @@ auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWra
}
template <class Function, class ...Args>
-[[nodiscard]]
+QTCONCURRENT_RUN_NODISCARD
auto run(Function &&f, Args &&...args)
{
return run(QThreadPool::globalInstance(), std::forward<Function>(f),
@@ -60,7 +67,7 @@ auto run(Function &&f, Args &&...args)
// overload with a Promise Type hint, takes thread pool
template <class PromiseType, class Function, class ...Args>
-[[nodiscard]]
+QTCONCURRENT_RUN_NODISCARD
auto run(QThreadPool *pool, Function &&f, Args &&...args)
{
return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(
@@ -69,16 +76,18 @@ auto run(QThreadPool *pool, Function &&f, Args &&...args)
// overload with a Promise Type hint, uses global thread pool
template <class PromiseType, class Function, class ...Args>
-[[nodiscard]]
+QTCONCURRENT_RUN_NODISCARD
auto run(Function &&f, Args &&...args)
{
return run<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f),
std::forward<Args>(args)...);
}
+#undef QTCONCURRENT_RUN_NODISCARD
+
} //namespace QtConcurrent
-#endif // Q_CLANG_QDOC
+#endif // Q_QDOC
QT_END_NAMESPACE
diff --git a/src/concurrent/qtconcurrenttask.h b/src/concurrent/qtconcurrenttask.h
index ed5109ede1..40a47918d7 100644
--- a/src/concurrent/qtconcurrenttask.h
+++ b/src/concurrent/qtconcurrenttask.h
@@ -10,7 +10,7 @@
QT_BEGIN_NAMESPACE
-#ifdef Q_CLANG_QDOC
+#ifdef Q_QDOC
namespace QtConcurrent {
@@ -30,7 +30,7 @@ constexpr auto task(Task &&t) { return QTaskBuilder(std::forward<Task>(t)); }
} // namespace QtConcurrent
-#endif // Q_CLANG_QDOC
+#endif // Q_QDOC
QT_END_NAMESPACE
diff --git a/src/concurrent/qtconcurrenttask.qdoc b/src/concurrent/qtconcurrenttask.qdoc
index 6f21ac1395..d3828b59c2 100644
--- a/src/concurrent/qtconcurrenttask.qdoc
+++ b/src/concurrent/qtconcurrenttask.qdoc
@@ -4,6 +4,7 @@
/*!
\page qtconcurrenttask.html
\title Concurrent Task
+ \brief A configurable way to run a task in a separate thread.
\ingroup thread
QtConcurrent::task provides an alternative interface for running a
diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp
index 5c120d676e..ce02d0c2c9 100644
--- a/src/concurrent/qtconcurrentthreadengine.cpp
+++ b/src/concurrent/qtconcurrentthreadengine.cpp
@@ -3,7 +3,7 @@
#include "qtconcurrentthreadengine.h"
-#if !defined(QT_NO_CONCURRENT) || defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
QT_BEGIN_NAMESPACE
@@ -63,6 +63,7 @@ void ThreadEngineBarrier::acquire()
if (count.testAndSetOrdered(localCount, localCount + 1))
return;
}
+ qYieldCpu();
}
}
@@ -82,6 +83,7 @@ int ThreadEngineBarrier::release()
if (count.testAndSetOrdered(localCount, localCount - 1))
return localCount - 1;
}
+ qYieldCpu();
}
}
@@ -98,6 +100,7 @@ void ThreadEngineBarrier::wait()
semaphore.acquire();
return;
}
+ qYieldCpu();
}
}
@@ -121,6 +124,7 @@ bool ThreadEngineBarrier::releaseUnlessLast()
if (count.testAndSetOrdered(localCount, localCount - 1))
return true;
}
+ qYieldCpu();
}
}
diff --git a/src/concurrent/qtconcurrentthreadengine.h b/src/concurrent/qtconcurrentthreadengine.h
index beca149303..14e1cf375b 100644
--- a/src/concurrent/qtconcurrentthreadengine.h
+++ b/src/concurrent/qtconcurrentthreadengine.h
@@ -6,7 +6,7 @@
#include <QtConcurrent/qtconcurrent_global.h>
-#if !defined(QT_NO_CONCURRENT) ||defined(Q_CLANG_QDOC)
+#if !defined(QT_NO_CONCURRENT) ||defined(Q_QDOC)
#include <QtCore/qthreadpool.h>
#include <QtCore/qfuture.h>