rt/emul/compact/src/main/java/java/io/BufferedInputStream.java
changeset 1337 c794024954b5
parent 1334 588d5bf7a560
     1.1 --- a/rt/emul/compact/src/main/java/java/io/BufferedInputStream.java	Thu Oct 03 15:40:35 2013 +0200
     1.2 +++ b/rt/emul/compact/src/main/java/java/io/BufferedInputStream.java	Thu Oct 03 17:36:44 2013 +0200
     1.3 @@ -24,7 +24,6 @@
     1.4   */
     1.5  
     1.6  package java.io;
     1.7 -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
     1.8  
     1.9  /**
    1.10   * A <code>BufferedInputStream</code> adds
    1.11 @@ -59,16 +58,6 @@
    1.12       */
    1.13      protected volatile byte buf[];
    1.14  
    1.15 -    /**
    1.16 -     * Atomic updater to provide compareAndSet for buf. This is
    1.17 -     * necessary because closes can be asynchronous. We use nullness
    1.18 -     * of buf[] as primary indicator that this stream is closed. (The
    1.19 -     * "in" field is also nulled out on close.)
    1.20 -     */
    1.21 -    private static final
    1.22 -        AtomicReferenceFieldUpdater<BufferedInputStream, byte[]> bufUpdater =
    1.23 -        AtomicReferenceFieldUpdater.newUpdater
    1.24 -        (BufferedInputStream.class,  byte[].class, "buf");
    1.25  
    1.26      /**
    1.27       * The index one greater than the index of the last valid byte in
    1.28 @@ -221,14 +210,6 @@
    1.29                      nsz = marklimit;
    1.30                  byte nbuf[] = new byte[nsz];
    1.31                  System.arraycopy(buffer, 0, nbuf, 0, pos);
    1.32 -                if (!bufUpdater.compareAndSet(this, buffer, nbuf)) {
    1.33 -                    // Can't replace buf if there was an async close.
    1.34 -                    // Note: This would need to be changed if fill()
    1.35 -                    // is ever made accessible to multiple threads.
    1.36 -                    // But for now, the only way CAS can fail is via close.
    1.37 -                    // assert buf == null;
    1.38 -                    throw new IOException("Stream closed");
    1.39 -                }
    1.40                  buffer = nbuf;
    1.41              }
    1.42          count = pos;
    1.43 @@ -465,13 +446,12 @@
    1.44      public void close() throws IOException {
    1.45          byte[] buffer;
    1.46          while ( (buffer = buf) != null) {
    1.47 -            if (bufUpdater.compareAndSet(this, buffer, null)) {
    1.48 -                InputStream input = in;
    1.49 -                in = null;
    1.50 -                if (input != null)
    1.51 -                    input.close();
    1.52 -                return;
    1.53 -            }
    1.54 +            InputStream input = in;
    1.55 +            buf = null;
    1.56 +            in = null;
    1.57 +            if (input != null)
    1.58 +                input.close();
    1.59 +            return;
    1.60              // Else retry in case a new buf was CASed in fill()
    1.61          }
    1.62      }