From 7694c718dbeaea869a8e5c5d8510cfa307273ee4 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 20 Mar 2017 11:43:50 +0100 Subject: [PATCH] MapReduce: Optimize cancelling between thread start and exec() call The existing logic works because the future watcher gets the canceled signal even if the future was canceled before connecting the watcher and starting the loop, and we schedule jobs before we start the loop and the watcher gets the signal. But it is still better to avoid scheduling anything at all in this case. Change-Id: I3fa722bdd8391de7c7f3ba3fd8b1aaa65d9d2392 Reviewed-by: Christian Stenger --- src/libs/utils/mapreduce.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/mapreduce.h b/src/libs/utils/mapreduce.h index 9f655a5aa0e..8c5452f79dc 100644 --- a/src/libs/utils/mapreduce.h +++ b/src/libs/utils/mapreduce.h @@ -77,7 +77,8 @@ public: void exec() { - if (schedule()) // do not enter event loop for empty containers + // do not enter event loop for empty containers or if already canceled + if (!m_futureInterface.isCanceled() && schedule()) m_loop.exec(); }