QtConcurrent::run: point return value ignorers to QThreadPool::start(Callable&&)
Use the new Q_NODISCARD_X macro to point users that ignore the QFuture returned from QtConcurrent::run() to QThreadPool::start(), which does the same thing, but doesn't return a future, so is better suited for the fire-and-forget use-case the OP of and commentators on QTBUG-111875 cited. Can't pick to older branches, since Q_NODISCARD_X is 6.7+. Task-number: QTBUG-111875 Change-Id: If0bf920ecc0fb59b9a9a9931ea9dc30f7abff1b7 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
f8cb42e391
commit
c1a95d1d0c
@ -35,8 +35,11 @@ namespace QtConcurrent {
|
||||
|
||||
namespace QtConcurrent {
|
||||
|
||||
#define QTCONCURRENT_RUN_NODISCARD \
|
||||
Q_NODISCARD_X("Use QThreadPool::start(Callable&&) if you don't need the returned QFuture")
|
||||
|
||||
template <class Function, class ...Args>
|
||||
[[nodiscard]]
|
||||
QTCONCURRENT_RUN_NODISCARD
|
||||
auto run(QThreadPool *pool, Function &&f, Args &&...args)
|
||||
{
|
||||
DecayedTuple<Function, Args...> tuple { std::forward<Function>(f),
|
||||
@ -46,7 +49,7 @@ auto run(QThreadPool *pool, Function &&f, Args &&...args)
|
||||
}
|
||||
|
||||
template <class Function, class ...Args>
|
||||
[[nodiscard]]
|
||||
QTCONCURRENT_RUN_NODISCARD
|
||||
auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWrapper,
|
||||
Args &&...args)
|
||||
{
|
||||
@ -55,7 +58,7 @@ auto run(QThreadPool *pool, std::reference_wrapper<const Function> &&functionWra
|
||||
}
|
||||
|
||||
template <class Function, class ...Args>
|
||||
[[nodiscard]]
|
||||
QTCONCURRENT_RUN_NODISCARD
|
||||
auto run(Function &&f, Args &&...args)
|
||||
{
|
||||
return run(QThreadPool::globalInstance(), std::forward<Function>(f),
|
||||
@ -64,7 +67,7 @@ auto run(Function &&f, Args &&...args)
|
||||
|
||||
// overload with a Promise Type hint, takes thread pool
|
||||
template <class PromiseType, class Function, class ...Args>
|
||||
[[nodiscard]]
|
||||
QTCONCURRENT_RUN_NODISCARD
|
||||
auto run(QThreadPool *pool, Function &&f, Args &&...args)
|
||||
{
|
||||
return (new StoredFunctionCallWithPromise<Function, PromiseType, Args...>(
|
||||
@ -73,13 +76,15 @@ auto run(QThreadPool *pool, Function &&f, Args &&...args)
|
||||
|
||||
// overload with a Promise Type hint, uses global thread pool
|
||||
template <class PromiseType, class Function, class ...Args>
|
||||
[[nodiscard]]
|
||||
QTCONCURRENT_RUN_NODISCARD
|
||||
auto run(Function &&f, Args &&...args)
|
||||
{
|
||||
return run<PromiseType>(QThreadPool::globalInstance(), std::forward<Function>(f),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#undef QTCONCURRENT_RUN_NODISCARD
|
||||
|
||||
} //namespace QtConcurrent
|
||||
|
||||
#endif // Q_QDOC
|
||||
|
Loading…
Reference in New Issue
Block a user