< prev index next >
src/java.base/share/classes/java/nio/channels/spi/AbstractSelectableChannel.java
Print this page
rev 48757 : [mq]: nio-cleanup
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -24,11 +24,18 @@
*/
package java.nio.channels.spi;
import java.io.IOException;
-import java.nio.channels.*;
+import java.nio.channels.CancelledKeyException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.IllegalSelectorException;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
/**
* Base implementation class for selectable channels.
*
@@ -65,12 +72,12 @@
private final Object keyLock = new Object();
// Lock for registration and configureBlocking operations
private final Object regLock = new Object();
- // Blocking mode, protected by regLock
- boolean blocking = true;
+ // Blocking mode, need regLock to change;
+ private volatile boolean nonBlocking;
/**
* Initializes a new instance of this class.
*
* @param provider
@@ -195,11 +202,11 @@
synchronized (regLock) {
if (!isOpen())
throw new ClosedChannelException();
if ((ops & ~validOps()) != 0)
throw new IllegalArgumentException();
- if (blocking)
+ if (isBlocking())
throw new IllegalBlockingModeException();
SelectionKey k = findKey(sel);
if (k != null) {
k.interestOps(ops);
k.attach(att);
@@ -262,13 +269,11 @@
// -- Blocking --
public final boolean isBlocking() {
- synchronized (regLock) {
- return blocking;
- }
+ return !nonBlocking;
}
public final Object blockingLock() {
return regLock;
}
@@ -285,16 +290,17 @@
throws IOException
{
synchronized (regLock) {
if (!isOpen())
throw new ClosedChannelException();
- if (blocking == block)
- return this;
+ boolean blocking = !nonBlocking;
+ if (block != blocking) {
if (block && haveValidKeys())
throw new IllegalBlockingModeException();
implConfigureBlocking(block);
- blocking = block;
+ nonBlocking = !block;
+ }
}
return this;
}
/**
< prev index next >