--- a/jdk/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java Fri Oct 10 10:58:08 2008 +0200
+++ b/jdk/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java Mon Oct 13 14:45:27 2008 -0700
@@ -46,15 +46,15 @@
// The poll object
DevPollArrayWrapper pollWrapper;
- // The number of valid channels in this Selector's poll array
- private int totalChannels;
-
// Maps from file descriptors to keys
private Map<Integer,SelectionKeyImpl> fdToKey;
// True if this Selector has been closed
private boolean closed = false;
+ // Lock for close/cleanup
+ private Object closeLock = new Object();
+
// Lock for interrupt triggering and clearing
private Object interruptLock = new Object();
private boolean interruptTriggered = false;
@@ -72,7 +72,6 @@
pollWrapper = new DevPollArrayWrapper();
pollWrapper.initInterrupt(fd0, fd1);
fdToKey = new HashMap<Integer,SelectionKeyImpl>();
- totalChannels = 1;
}
protected int doSelect(long timeout)
@@ -131,45 +130,39 @@
}
protected void implClose() throws IOException {
- if (!closed) {
- closed = true;
-
- // prevent further wakeup
- synchronized (interruptLock) {
- interruptTriggered = true;
- }
+ if (closed)
+ return;
+ closed = true;
- FileDispatcher.closeIntFD(fd0);
- FileDispatcher.closeIntFD(fd1);
- if (pollWrapper != null) {
+ // prevent further wakeup
+ synchronized (interruptLock) {
+ interruptTriggered = true;
+ }
- pollWrapper.release(fd0);
- pollWrapper.closeDevPollFD();
- pollWrapper = null;
- selectedKeys = null;
+ FileDispatcher.closeIntFD(fd0);
+ FileDispatcher.closeIntFD(fd1);
- // Deregister channels
- Iterator i = keys.iterator();
- while (i.hasNext()) {
- SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
- deregister(ski);
- SelectableChannel selch = ski.channel();
- if (!selch.isOpen() && !selch.isRegistered())
- ((SelChImpl)selch).kill();
- i.remove();
- }
- totalChannels = 0;
+ pollWrapper.release(fd0);
+ pollWrapper.closeDevPollFD();
+ selectedKeys = null;
- }
- fd0 = -1;
- fd1 = -1;
+ // Deregister channels
+ Iterator i = keys.iterator();
+ while (i.hasNext()) {
+ SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
+ deregister(ski);
+ SelectableChannel selch = ski.channel();
+ if (!selch.isOpen() && !selch.isRegistered())
+ ((SelChImpl)selch).kill();
+ i.remove();
}
+ fd0 = -1;
+ fd1 = -1;
}
protected void implRegister(SelectionKeyImpl ski) {
int fd = IOUtil.fdVal(ski.channel.getFD());
fdToKey.put(Integer.valueOf(fd), ski);
- totalChannels++;
keys.add(ski);
}
@@ -179,7 +172,6 @@
int fd = ski.channel.getFDVal();
fdToKey.remove(Integer.valueOf(fd));
pollWrapper.release(fd);
- totalChannels--;
ski.setIndex(-1);
keys.remove(ski);
selectedKeys.remove(ski);
@@ -190,6 +182,8 @@
}
void putEventOps(SelectionKeyImpl sk, int ops) {
+ if (closed)
+ throw new ClosedSelectorException();
int fd = IOUtil.fdVal(sk.channel.getFD());
pollWrapper.setInterest(fd, ops);
}