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
tags/v3.0.0.201305080800-m7
Shawn Pearce 11 years ago
parent
commit
d01fe32795

+ 2
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java View File

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

+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/lib/ThreadSafeProgressMonitor.java View File

@@ -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