Skip to content

Commit 9493d47

Browse files
committed
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 <[email protected]> Reviewed-by: Orgad Shaneh <[email protected]>
1 parent 67153b2 commit 9493d47

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libs/utils/runextensions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con
512512
const ReduceFunction &reduce, const CleanUpFunction &cleanup)
513513
{
514514
auto state = init(futureInterface);
515-
futureInterface.reportStarted();
516515
mapReduceLoop(futureInterface, container, map, state, reduce);
517516
cleanup(futureInterface, state);
518517
if (futureInterface.isPaused())
@@ -523,7 +522,6 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con
523522
template <typename ResultType, typename Function, typename... Args>
524523
void runAsyncImpl(QFutureInterface<ResultType> futureInterface, const Function &function, const Args&... args)
525524
{
526-
futureInterface.reportStarted();
527525
function(futureInterface, args...);
528526
if (futureInterface.isPaused())
529527
futureInterface.waitForResume();
@@ -540,6 +538,7 @@ QFuture<ReduceResult> mapReduce(std::reference_wrapper<Container> containerWrapp
540538
{
541539
auto fi = QFutureInterface<ReduceResult>();
542540
QFuture<ReduceResult> future = fi.future();
541+
fi.reportStarted();
543542
std::thread(Internal::blockingMapReduce<Container, InitFunction, MapFunction, ReduceResult, ReduceFunction, CleanUpFunction>,
544543
fi, containerWrapper, init, map, reduce, cleanup).detach();
545544
return future;
@@ -561,6 +560,7 @@ template <typename ResultType, typename Function, typename... Args>
561560
QFuture<ResultType> runAsync(Function &&function, Args&&... args)
562561
{
563562
QFutureInterface<ResultType> futureInterface;
563+
futureInterface.reportStarted();
564564
std::thread(Internal::runAsyncImpl<ResultType,Function,Args...>, futureInterface,
565565
std::forward<Function>(function), std::forward<Args>(args)...).detach();
566566
return futureInterface.future();

0 commit comments

Comments
 (0)