Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtconcurrentrun.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QTCONCURRENT_RUN_H
6#define QTCONCURRENT_RUN_H
7
8#if 0
9#pragma qt_class(QtConcurrentRun)
10#endif
11
12#include <QtConcurrent/qtconcurrentcompilertest.h>
13
14#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
15
16#include <QtConcurrent/qtconcurrentrunbase.h>
17#include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
18
19QT_BEGIN_NAMESPACE
20
21#ifdef Q_QDOC
22
23typedef int Function;
24
25namespace QtConcurrent {
26
27 template <typename T>
28 QFuture<T> run(Function function, ...);
29
30 template <typename T>
31 QFuture<T> run(QThreadPool *pool, Function function, ...);
32
33} // namespace QtConcurrent
34
35#else
36
37namespace QtConcurrent {
38
39#define QTCONCURRENT_RUN_NODISCARD
40 Q_NODISCARD_X("Use QThreadPool::start(Callable&&) if you don't need the returned QFuture")
41
42template <class Function, class ...Args>
44auto run(QThreadPool *pool, Function &&f, Args &&...args)
45{
46 DecayedTuple<Function, Args...> tuple { std::forward<Function>(f),
47 std::forward<Args>(args)... };
48 return TaskResolver<std::decay_t<Function>, std::decay_t<Args>...>::run(
49 std::move(tuple), TaskStartParameters { pool });
50}
51
52template <class Function, class ...Args>
55 Args &&...args)
56{
57 return run(pool, std::forward<const Function>(functionWrapper.get()),
58 std::forward<Args>(args)...);
59}
60
61template <class Function, class ...Args>
63auto run(Function &&f, Args &&...args)
64{
65 return run(QThreadPool::globalInstance(), std::forward<Function>(f),
66 std::forward<Args>(args)...);
67}
68
69// overload with a Promise Type hint, takes thread pool
70template <class PromiseType, class Function, class ...Args>
72auto run(QThreadPool *pool, Function &&f, Args &&...args)
73{
74 return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(
75 std::forward<Function>(f), std::forward<Args>(args)...))->start(pool);
76}
77
78// overload with a Promise Type hint, uses global thread pool
79template <class PromiseType, class Function, class ...Args>
81auto run(Function &&f, Args &&...args)
82{
83 return run<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f),
84 std::forward<Args>(args)...);
85}
86
87#undef QTCONCURRENT_RUN_NODISCARD
88
89} //namespace QtConcurrent
90
91#endif // Q_QDOC
92
93QT_END_NAMESPACE
94
95#endif // QT_NO_CONCURRENT
96
97#endif
\inmodule QtConcurrent
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args)
QTCONCURRENT_RUN_NODISCARD auto run(Function &&f, Args &&...args)
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, std::reference_wrapper< const Function > &&functionWrapper, Args &&...args)
#define QTCONCURRENT_RUN_NODISCARD