From 6cc3ef9d46aa6fa53aee6d10bcfcbc9894c69f29 Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 14 Jul 2010 15:42:59 +0400 Subject: [PATCH] SVN: one-click merge: concurrent tasks fix (cherry picked from commit dc8f5fdb7be1d4e8f8c98951594885354f4269cc) --- .../intellij/openapi/vcs/ConcurrentTasks.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/ConcurrentTasks.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ConcurrentTasks.java index 8f06af722b6f..8ad878e809e7 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/ConcurrentTasks.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/ConcurrentTasks.java @@ -17,7 +17,6 @@ package com.intellij.openapi.vcs; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.util.Consumer; @@ -51,7 +50,10 @@ public class ConcurrentTasks { final List> futures = new LinkedList>(); for (final Consumer> task : myTasks) { - if (myResultKnown) break; + if (myResultKnown) { + -- myCntAlive; + continue; + } final Runnable computableProxy = new Runnable() { public void run() { try { @@ -60,17 +62,14 @@ public class ConcurrentTasks { if (myResultKnown) return; myResult = t; myResultKnown = true; - -- myCntAlive; - mySemaphore.up(); } }); } - catch (ProcessCanceledException e) { + finally { -- myCntAlive; - if (myCntAlive == 0) { + if (myCntAlive == 0 || myResultKnown) { mySemaphore.up(); } - throw e; } } }; @@ -83,9 +82,10 @@ public class ConcurrentTasks { } while (true) { - mySemaphore.waitFor(1000); if (myResultKnown) break; + if (myCntAlive <= 0) break; pi.checkCanceled(); + mySemaphore.waitFor(1000); } // in it possible to even interrupt() threads involved, but at the moment it's better for tasks themselves to check cancel status for (Future future : futures) {