From c1a95d1d0c6b52337a806f49eb7e7507055bcaeb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Jul 2023 14:41:29 +0200 Subject: [PATCH] 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 --- src/concurrent/qtconcurrentrun.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/concurrent/qtconcurrentrun.h b/src/concurrent/qtconcurrentrun.h index cf153ab34e6..cbc750de84f 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 -[[nodiscard]] +QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args) { DecayedTuple tuple { std::forward(f), @@ -46,7 +49,7 @@ auto run(QThreadPool *pool, Function &&f, Args &&...args) } template -[[nodiscard]] +QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, std::reference_wrapper &&functionWrapper, Args &&...args) { @@ -55,7 +58,7 @@ auto run(QThreadPool *pool, std::reference_wrapper &&functionWra } template -[[nodiscard]] +QTCONCURRENT_RUN_NODISCARD auto run(Function &&f, Args &&...args) { return run(QThreadPool::globalInstance(), std::forward(f), @@ -64,7 +67,7 @@ auto run(Function &&f, Args &&...args) // overload with a Promise Type hint, takes thread pool template -[[nodiscard]] +QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args) { return (new StoredFunctionCallWithPromise( @@ -73,13 +76,15 @@ auto run(QThreadPool *pool, Function &&f, Args &&...args) // overload with a Promise Type hint, uses global thread pool template -[[nodiscard]] +QTCONCURRENT_RUN_NODISCARD auto run(Function &&f, Args &&...args) { return run(QThreadPool::globalInstance(), std::forward(f), std::forward(args)...); } +#undef QTCONCURRENT_RUN_NODISCARD + } //namespace QtConcurrent #endif // Q_QDOC