diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-07-27 14:41:29 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-07-31 20:09:03 +0000 |
commit | c1a95d1d0c6b52337a806f49eb7e7507055bcaeb (patch) | |
tree | 1f7b3030c98f619ca3e4d283721e2b9c39fe7144 | |
parent | f8cb42e39196866c63cfe095dd552d07c70ccb62 (diff) |
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>
-rw-r--r-- | src/concurrent/qtconcurrentrun.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/concurrent/qtconcurrentrun.h b/src/concurrent/qtconcurrentrun.h index cf153ab34e..cbc750de84 100644 --- a/src/concurrent/qtconcurrentrun.h +++ b/src/concurrent/qtconcurrentrun.h @@ -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 |