File indexing completed on 2026-01-07 10:15:53
0001
0002
0003
0004
0005 #ifndef QTCONCURRENT_RUN_H
0006 #define QTCONCURRENT_RUN_H
0007
0008 #if 0
0009 #pragma qt_class(QtConcurrentRun)
0010 #endif
0011
0012 #include <QtConcurrent/qtconcurrentcompilertest.h>
0013
0014 #if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
0015
0016 #include <QtConcurrent/qtconcurrentrunbase.h>
0017 #include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
0018
0019 QT_BEGIN_NAMESPACE
0020
0021 #ifdef Q_QDOC
0022
0023 typedef int Function;
0024
0025 namespace QtConcurrent {
0026
0027 template <typename T>
0028 QFuture<T> run(Function function, ...);
0029
0030 template <typename T>
0031 QFuture<T> run(QThreadPool *pool, Function function, ...);
0032
0033 }
0034
0035 #else
0036
0037 namespace QtConcurrent {
0038
0039 #define QTCONCURRENT_RUN_NODISCARD \
0040 Q_NODISCARD_X("Use QThreadPool::start(Callable&&) if you don't need the returned QFuture")
0041
0042 template <class Function, class ...Args>
0043 QTCONCURRENT_RUN_NODISCARD
0044 auto run(QThreadPool *pool, Function &&f, Args &&...args)
0045 {
0046 DecayedTuple<Function, Args...> tuple { std::forward<Function>(f),
0047 std::forward<Args>(args)... };
0048 return TaskResolver<std::decay_t<Function>, std::decay_t<Args>...>::run(
0049 std::move(tuple), TaskStartParameters { pool });
0050 }
0051
0052 template <class Function, class ...Args>
0053 QTCONCURRENT_RUN_NODISCARD
0054 auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWrapper,
0055 Args &&...args)
0056 {
0057 return run(pool, std::forward<const Function>(functionWrapper.get()),
0058 std::forward<Args>(args)...);
0059 }
0060
0061 template <class Function, class ...Args>
0062 QTCONCURRENT_RUN_NODISCARD
0063 auto run(Function &&f, Args &&...args)
0064 {
0065 return run(QThreadPool::globalInstance(), std::forward<Function>(f),
0066 std::forward<Args>(args)...);
0067 }
0068
0069
0070 template <class PromiseType, class Function, class ...Args>
0071 QTCONCURRENT_RUN_NODISCARD
0072 auto run(QThreadPool *pool, Function &&f, Args &&...args)
0073 {
0074 return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(
0075 std::forward<Function>(f), std::forward<Args>(args)...))->start(pool);
0076 }
0077
0078
0079 template <class PromiseType, class Function, class ...Args>
0080 QTCONCURRENT_RUN_NODISCARD
0081 auto run(Function &&f, Args &&...args)
0082 {
0083 return run<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f),
0084 std::forward<Args>(args)...);
0085 }
0086
0087 #undef QTCONCURRENT_RUN_NODISCARD
0088
0089 }
0090
0091 #endif
0092
0093 QT_END_NAMESPACE
0094
0095 #endif
0096
0097 #endif