diff options
author | Jonathan Nieder <jrn@google.com> | 2016-11-13 13:16:48 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2016-11-13 13:32:08 -0800 |
commit | 97f3baa0d3df7ed26a55b2240cc5ce1a04861a4c (patch) | |
tree | 1e0f9dd2743d2fb364b3c62ee3653828ac6e95df | |
parent | 6aa126ec427c1beba49143aceb712e04b3f2aea6 (diff) | |
download | jgit-97f3baa0d3df7ed26a55b2240cc5ce1a04861a4c.tar.gz jgit-97f3baa0d3df7ed26a55b2240cc5ce1a04861a4c.zip |
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
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java | 13 |
1 files changed, 1 insertions, 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; } |