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 cbded4673733..f38adc74ab98 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/ConcurrentTasks.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/ConcurrentTasks.java @@ -26,13 +26,14 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; // competes to calculate The Result public class ConcurrentTasks { private volatile boolean myResultKnown; private final Semaphore mySemaphore; private volatile T myResult; - private volatile int myCntAlive; + private AtomicInteger myCntAlive; private final ProgressIndicator myParentIndicator; private final List>> myTasks; @@ -46,13 +47,13 @@ public class ConcurrentTasks { super.checkCanceled(); } }; - myCntAlive = myTasks.size(); + myCntAlive = new AtomicInteger(myTasks.size()); mySemaphore.down(); final List> futures = new LinkedList>(); for (final Consumer> task : myTasks) { if (myResultKnown) { - -- myCntAlive; + myCntAlive.decrementAndGet(); continue; } final Runnable computableProxy = new Runnable() { @@ -67,8 +68,8 @@ public class ConcurrentTasks { }); } finally { - -- myCntAlive; - if (myCntAlive == 0 || myResultKnown) { + final int decremented = myCntAlive.decrementAndGet(); + if (decremented == 0 || myResultKnown) { mySemaphore.up(); } } @@ -84,7 +85,7 @@ public class ConcurrentTasks { while (true) { if (myResultKnown) break; - if (myCntAlive <= 0) break; + if (myCntAlive.get() <= 0) break; pi.checkCanceled(); mySemaphore.waitFor(300); }