Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:09:51

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