summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2013-04-10 09:41:55 -0700
committerShawn Pearce <spearce@spearce.org>2013-04-10 12:59:11 -0700
commitd01fe3279530a2939bf917d26e393efb85079ca1 (patch)
treedff3b715e4f4376d9eae07d215be44f31ac7eea3
parent66192817cd52c6f7049be4491787ca40923de014 (diff)
downloadjgit-d01fe3279530a2939bf917d26e393efb85079ca1.tar.gz
jgit-d01fe3279530a2939bf917d26e393efb85079ca1.zip
Skip main thread test in ThreadSafeProgressMonitor
update(int) is only invoked from a worker thread, in JGit's case this is DeltaTask. The Javadoc of TSPM suggests update should only ever be used by a worker thread. Skip the main thread check, saving some cycles on each run of the progress monitor. Change-Id: I6cb9382d71b4cb3f8e8981c7ac382da25304dfcb
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java5
2 files changed, 3 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
index b44970e358..2845f8acfe 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
@@ -104,9 +104,11 @@ public class ThreadSafeProgressMonitorTest {
assertEquals(42, mock.value);
pm.update(1);
+ pm.pollForUpdates();
assertEquals(43, mock.value);
pm.update(2);
+ pm.pollForUpdates();
assertEquals(45, mock.value);
pm.endTask();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java
index 9e8e256b01..ff85f9b8fd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java
@@ -157,10 +157,7 @@ public class ThreadSafeProgressMonitor implements ProgressMonitor {
}
public void update(int completed) {
- int old = pendingUpdates.getAndAdd(completed);
- if (isMainThread())
- doUpdates();
- else if (old == 0)
+ if (0 == pendingUpdates.getAndAdd(completed))
process.release();
}