src/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java

Print this page

        

*** 86,96 **** public abstract class AbstractInterruptibleChannel implements Channel, InterruptibleChannel { ! private Object closeLock = new Object(); private volatile boolean open = true; /** * Initializes a new instance of this class. */ --- 86,96 ---- public abstract class AbstractInterruptibleChannel implements Channel, InterruptibleChannel { ! private final Object closeLock = new Object(); private volatile boolean open = true; /** * Initializes a new instance of this class. */
*** 140,150 **** // -- Interruption machinery -- private Interruptible interruptor; ! private volatile boolean interrupted = false; /** * Marks the beginning of an I/O operation that might block indefinitely. * * <p> This method should be invoked in tandem with the {@link #end end} --- 140,150 ---- // -- Interruption machinery -- private Interruptible interruptor; ! private volatile Thread interrupted; /** * Marks the beginning of an I/O operation that might block indefinitely. * * <p> This method should be invoked in tandem with the {@link #end end}
*** 153,177 **** * closing and interruption for this channel. </p> */ protected final void begin() { if (interruptor == null) { interruptor = new Interruptible() { ! public void interrupt() { synchronized (closeLock) { if (!open) return; - interrupted = true; open = false; try { AbstractInterruptibleChannel.this.implCloseChannel(); } catch (IOException x) { } } }}; } blockedOn(interruptor); ! if (Thread.currentThread().isInterrupted()) ! interruptor.interrupt(); } /** * Marks the end of an I/O operation that might block indefinitely. * --- 153,178 ---- * closing and interruption for this channel. </p> */ protected final void begin() { if (interruptor == null) { interruptor = new Interruptible() { ! public void interrupt(Thread target) { synchronized (closeLock) { if (!open) return; open = false; + interrupted = target; try { AbstractInterruptibleChannel.this.implCloseChannel(); } catch (IOException x) { } } }}; } blockedOn(interruptor); ! Thread me = Thread.currentThread(); ! if (me.isInterrupted()) ! interruptor.interrupt(me); } /** * Marks the end of an I/O operation that might block indefinitely. *
*** 193,208 **** */ protected final void end(boolean completed) throws AsynchronousCloseException { blockedOn(null); ! if (completed) { ! interrupted = false; ! return; } ! if (interrupted) throw new ClosedByInterruptException(); ! if (!open) throw new AsynchronousCloseException(); } // -- sun.misc.SharedSecrets -- static void blockedOn(Interruptible intr) { // package-private --- 194,210 ---- */ protected final void end(boolean completed) throws AsynchronousCloseException { blockedOn(null); ! Thread interrupted = this.interrupted; ! if (interrupted != null && interrupted == Thread.currentThread()) { ! interrupted = null; ! throw new ClosedByInterruptException(); } ! if (!completed && !open) ! throw new AsynchronousCloseException(); } // -- sun.misc.SharedSecrets -- static void blockedOn(Interruptible intr) { // package-private