Browse Source

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
stable-3.0
Shawn Pearce 12 years ago
parent
commit
d01fe32795
  1. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
  2. 5
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java

2
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();

5
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();
}

Loading…
Cancel
Save