From 9493d4764b4b4d3400b0ecfca96add85a4adc320 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 14 Jan 2016 15:52:49 +0100 Subject: [PATCH] mapReduce/runAsync: Fix behavior of waitForFinished When a QFutureInterface is constructed, it is in "NoState", but waitForFinished only blocks if it is in "Running" state. So we need to reportStarted actually before the thread is started (so we report it before leaving the mapReduce/runAsync method) Change-Id: I1cdf0d627c5a6c26797b04fd0d331cddb01d50af Reviewed-by: Nikolai Kosjar Reviewed-by: Orgad Shaneh --- src/libs/utils/runextensions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/runextensions.h b/src/libs/utils/runextensions.h index 82854abd731..af174a32e26 100644 --- a/src/libs/utils/runextensions.h +++ b/src/libs/utils/runextensions.h @@ -512,7 +512,6 @@ void blockingMapReduce(QFutureInterface futureInterface, const Con const ReduceFunction &reduce, const CleanUpFunction &cleanup) { auto state = init(futureInterface); - futureInterface.reportStarted(); mapReduceLoop(futureInterface, container, map, state, reduce); cleanup(futureInterface, state); if (futureInterface.isPaused()) @@ -523,7 +522,6 @@ void blockingMapReduce(QFutureInterface futureInterface, const Con template void runAsyncImpl(QFutureInterface futureInterface, const Function &function, const Args&... args) { - futureInterface.reportStarted(); function(futureInterface, args...); if (futureInterface.isPaused()) futureInterface.waitForResume(); @@ -540,6 +538,7 @@ QFuture mapReduce(std::reference_wrapper containerWrapp { auto fi = QFutureInterface(); QFuture future = fi.future(); + fi.reportStarted(); std::thread(Internal::blockingMapReduce, fi, containerWrapper, init, map, reduce, cleanup).detach(); return future; @@ -561,6 +560,7 @@ template QFuture runAsync(Function &&function, Args&&... args) { QFutureInterface futureInterface; + futureInterface.reportStarted(); std::thread(Internal::runAsyncImpl, futureInterface, std::forward(function), std::forward(args)...).detach(); return futureInterface.future();