From 97f3baa0d3df7ed26a55b2240cc5ce1a04861a4c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 13 Nov 2016 13:16:48 -0800 Subject: StreamCopyThread: Remove unnecessary flushCount StreamCopyThread#run consistently interrupts itself whenever it discovers it has been interrupted by StreamCopyThread#flush while not reading. The flushCount is not needed to avoid lost flushes. All in-tree users of StreamCopyThread never flush. As a nice side benefit, this avoids the expense of atomic operations that have no purpose for those users. Change-Id: I1afe415cd09a67f1891c3baf712a9003ad553062 --- .../src/org/eclipse/jgit/util/io/StreamCopyThread.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java index 506330eb08..fdb2a036c5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java @@ -59,8 +59,6 @@ public class StreamCopyThread extends Thread { private volatile boolean done; - private final AtomicInteger flushCount = new AtomicInteger(0); - /** Lock held by flush to avoid interrupting a write. */ private final Object writeLock; @@ -90,7 +88,6 @@ public class StreamCopyThread extends Thread { */ @Deprecated public void flush() { - flushCount.incrementAndGet(); synchronized (writeLock) { interrupt(); } @@ -120,7 +117,6 @@ public class StreamCopyThread extends Thread { public void run() { try { final byte[] buf = new byte[BUFFER_SIZE]; - int flushCountBeforeRead = 0; boolean readInterrupted = false; for (;;) { try { @@ -133,18 +129,11 @@ public class StreamCopyThread extends Thread { } } readInterrupted = false; - if (!flushCount.compareAndSet(flushCountBeforeRead, 0)) { - // There was a flush() call since last blocked read. - // Set interrupt status, so next blocked read will throw - // an InterruptedIOException and we will flush again. - interrupt(); - } } if (done) break; - flushCountBeforeRead = flushCount.get(); final int n; try { n = src.read(buf); @@ -167,7 +156,7 @@ public class StreamCopyThread extends Thread { // set interrupt status, which will be checked // when we block in src.read - if (writeInterrupted || flushCount.get() > 0) + if (writeInterrupted) interrupt(); break; } -- cgit v1.2.3