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.txt2
-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.qdoc2
-rw-r--r--src/concurrent/qtconcurrentiteratekernel.cpp2
-rw-r--r--src/concurrent/qtconcurrentiteratekernel.h8
-rw-r--r--src/concurrent/qtconcurrentreducekernel.h2
-rw-r--r--src/concurrent/qtconcurrentrun.cpp15
-rw-r--r--src/concurrent/qtconcurrentrun.h15
-rw-r--r--src/concurrent/qtconcurrentthreadengine.cpp4
14 files changed, 61 insertions, 28 deletions
diff --git a/src/concurrent/CMakeLists.txt b/src/concurrent/CMakeLists.txt
index cb007538b6..8c852f9ae5 100644
--- a/src/concurrent/CMakeLists.txt
+++ b/src/concurrent/CMakeLists.txt
@@ -1,8 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-# Generated from concurrent.pro.
-
#####################################################################
## Concurrent Module:
#####################################################################
@@ -27,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
@@ -37,7 +37,6 @@ qt_internal_add_module(Concurrent
Qt::CorePrivate
PRECOMPILED_HEADER
"../corelib/global/qt_pch.h"
- GENERATE_CPP_EXPORTS
)
## Scopes:
@@ -50,4 +49,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 d1cc570d62..03ebb75a2e 100644
--- a/src/concurrent/doc/snippets/CMakeLists.txt
+++ b/src/concurrent/doc/snippets/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#! [cmake_use]
find_package(Qt6 REQUIRED COMPONENTS 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.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/qtconcurrentiteratekernel.cpp b/src/concurrent/qtconcurrentiteratekernel.cpp
index 088c8384ce..00228f181c 100644
--- a/src/concurrent/qtconcurrentiteratekernel.cpp
+++ b/src/concurrent/qtconcurrentiteratekernel.cpp
@@ -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 a23fe37a3c..232f4c8bfe 100644
--- a/src/concurrent/qtconcurrentiteratekernel.h
+++ b/src/concurrent/qtconcurrentiteratekernel.h
@@ -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/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h
index cb7d7910aa..c337a9192f 100644
--- a/src/concurrent/qtconcurrentreducekernel.h
+++ b/src/concurrent/qtconcurrentreducekernel.h
@@ -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,
diff --git a/src/concurrent/qtconcurrentrun.cpp b/src/concurrent/qtconcurrentrun.cpp
index fc19b947e5..017f2df480 100644
--- a/src/concurrent/qtconcurrentrun.cpp
+++ b/src/concurrent/qtconcurrentrun.cpp
@@ -80,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
@@ -220,7 +224,7 @@
*/
/*!
- \fn QFuture<T> QtConcurrent::run(Function function, ...);
+ \fn template <typename T> QFuture<T> QtConcurrent::run(Function function, ...);
Equivalent to
\code
@@ -251,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 cf153ab34e..cbc750de84 100644
--- a/src/concurrent/qtconcurrentrun.h
+++ b/src/concurrent/qtconcurrentrun.h
@@ -35,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),
@@ -46,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)
{
@@ -55,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),
@@ -64,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...>(
@@ -73,13 +76,15 @@ 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_QDOC
diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp
index d10cca5de7..ce02d0c2c9 100644
--- a/src/concurrent/qtconcurrentthreadengine.cpp
+++ b/src/concurrent/qtconcurrentthreadengine.cpp
@@ -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();
}
}