Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QTCONCURRENT_RUN_H
5#define QTCONCURRENT_RUN_H
6
7#if 0
8#pragma qt_class(QtConcurrentRun)
9#endif
10
11#include <QtConcurrent/qtconcurrentcompilertest.h>
12
13#if !defined(QT_NO_CONCURRENT) || defined(Q_QDOC)
14
15#include <QtConcurrent/qtconcurrentrunbase.h>
16#include <QtConcurrent/qtconcurrentstoredfunctioncall.h>
17
19
20#ifdef Q_QDOC
21
22typedef int Function;
23
24namespace QtConcurrent {
25
26 template <typename T>
27 QFuture<T> run(Function function, ...);
28
29 template <typename T>
30 QFuture<T> run(QThreadPool *pool, Function function, ...);
31
32} // namespace QtConcurrent
33
34#else
35
36namespace QtConcurrent {
37
38#define QTCONCURRENT_RUN_NODISCARD \
39 Q_NODISCARD_X("Use QThreadPool::start(Callable&&) if you don't need the returned QFuture")
40
41template <class Function, class ...Args>
43auto run(QThreadPool *pool, Function &&f, Args &&...args)
44{
45 DecayedTuple<Function, Args...> tuple { std::forward<Function>(f),
46 std::forward<Args>(args)... };
47 return TaskResolver<std::decay_t<Function>, std::decay_t<Args>...>::run(
48 std::move(tuple), TaskStartParameters { pool });
49}
50
51template <class Function, class ...Args>
53auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWrapper,
54 Args &&...args)
55{
56 return run(pool, std::forward<const Function>(functionWrapper.get()),
57 std::forward<Args>(args)...);
58}
59
60template <class Function, class ...Args>
62auto run(Function &&f, Args &&...args)
63{
64 return run(QThreadPool::globalInstance(), std::forward<Function>(f),
65 std::forward<Args>(args)...);
66}
67
68// overload with a Promise Type hint, takes thread pool
69template <class PromiseType, class Function, class ...Args>
71auto run(QThreadPool *pool, Function &&f, Args &&...args)
72{
73 return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(
74 std::forward<Function>(f), std::forward<Args>(args)...))->start(pool);
75}
76
77// overload with a Promise Type hint, uses global thread pool
78template <class PromiseType, class Function, class ...Args>
80auto run(Function &&f, Args &&...args)
81{
82 return run<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f),
83 std::forward<Args>(args)...);
84}
85
86#undef QTCONCURRENT_RUN_NODISCARD
87
88} //namespace QtConcurrent
89
90#endif // Q_QDOC
91
93
94#endif // QT_NO_CONCURRENT
95
96#endif
\inmodule QtCore
Definition qthreadpool.h:22
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
Combined button and popup list for selecting options.
\inmodule QtConcurrent
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args)
std::tuple< std::decay_t< Types >... > DecayedTuple
GLfloat GLfloat f
#define QTCONCURRENT_RUN_NODISCARD
QJSValueList args