diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-10-02 19:24:38 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-10-28 15:38:44 +0100 |
commit | cf043a785ac9357e8f1283ea9e1496261af2b1a5 (patch) | |
tree | e85e282dbfb839ab4185c7b44caefe7248509696 /src/concurrent/qtconcurrentrun.h | |
parent | bb8c24e467767e35cb104167689b96c0deea5639 (diff) |
QtConcurrent: Integrate runWithPromise into run
Change-Id: I6eb95aa66ff847e8bb9aac348fded3a5d55015b6
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/concurrent/qtconcurrentrun.h')
-rw-r--r-- | src/concurrent/qtconcurrentrun.h | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/src/concurrent/qtconcurrentrun.h b/src/concurrent/qtconcurrentrun.h index 79322b925f..4ce8d6ae05 100644 --- a/src/concurrent/qtconcurrentrun.h +++ b/src/concurrent/qtconcurrentrun.h @@ -77,55 +77,45 @@ template <class Function, class ...Args> [[nodiscard]] auto run(QThreadPool *pool, Function &&f, Args &&...args) { - return (new StoredFunctionCall<Function, Args...>( - std::forward<Function>(f), std::forward<Args>(args)...))->start(pool); + DecayedTuple<Function, Args...> tuple { std::forward<Function>(f), + std::forward<Args>(args)... }; + return TaskResolver<std::decay_t<Function>, std::decay_t<Args>...>::run( + std::move(tuple), TaskStartParameters { pool }); } template <class Function, class ...Args> [[nodiscard]] -auto run(Function &&f, Args &&...args) +auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWrapper, + Args &&...args) { - return run(QThreadPool::globalInstance(), std::forward<Function>(f), std::forward<Args>(args)...); -} - -template <class PromiseType, class Function, class ...Args> -[[nodiscard]] -auto runWithPromise(QThreadPool *pool, Function &&f, Args &&...args) -{ - return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>( - std::forward<Function>(f), std::forward<Args>(args)...))->start(pool); + return run(pool, std::forward<const Function>(functionWrapper.get()), + std::forward<Args>(args)...); } template <class Function, class ...Args> [[nodiscard]] -auto runWithPromise(QThreadPool *pool, Function &&f, Args &&...args) -{ - static_assert(QtPrivate::ArgResolver<Function>::IsPromise, "The first argument of passed callable object isn't a QPromise<T> & type."); - using PromiseType = typename QtPrivate::ArgResolver<Function>::PromiseType; - return runWithPromise<PromiseType>(pool, std::forward<Function>(f), std::forward<Args>(args)...); -} - -template <class Function, class ...Args> -[[nodiscard]] -auto runWithPromise(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWrapper, Args &&...args) +auto run(Function &&f, Args &&...args) { - static_assert(QtPrivate::ArgResolver<const Function>::IsPromise, "The first argument of passed callable object isn't a QPromise<T> & type."); - using PromiseType = typename QtPrivate::ArgResolver<const Function>::PromiseType; - return runWithPromise<PromiseType>(pool, std::forward<const Function>(functionWrapper.get()), std::forward<Args>(args)...); + return run(QThreadPool::globalInstance(), std::forward<Function>(f), + std::forward<Args>(args)...); } +// overload with a Promise Type hint, takes thread pool template <class PromiseType, class Function, class ...Args> [[nodiscard]] -auto runWithPromise(Function &&f, Args &&...args) +auto run(QThreadPool *pool, Function &&f, Args &&...args) { - return runWithPromise<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f), std::forward<Args>(args)...); + return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>( + std::forward<Function>(f), std::forward<Args>(args)...))->start(pool); } -template <class Function, class ...Args> +// overload with a Promise Type hint, uses global thread pool +template <class PromiseType, class Function, class ...Args> [[nodiscard]] -auto runWithPromise(Function &&f, Args &&...args) +auto run(Function &&f, Args &&...args) { - return runWithPromise(QThreadPool::globalInstance(), std::forward<Function>(f), std::forward<Args>(args)...); + return run<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f), + std::forward<Args>(args)...); } } //namespace QtConcurrent |