8200583: (se) Selector clean-up, part 4

Reviewed-by: bpb, chegar
This commit is contained in:
Alan Bateman 2018-04-05 15:01:57 +01:00
parent 9968548d57
commit d185d65b69
11 changed files with 156 additions and 269 deletions

View file

@ -64,7 +64,7 @@ class PollArrayWrapper {
// Prepare another pollfd struct for use.
void putEntry(int index, SelectionKeyImpl ski) {
putDescriptor(index, ski.channel.getFDVal());
putDescriptor(index, ski.getFDVal());
putEventOps(index, 0);
}

View file

@ -83,12 +83,12 @@ class WindowsSelectorImpl extends SelectorImpl {
return get(Integer.valueOf(desc));
}
private MapEntry put(SelectionKeyImpl ski) {
return put(Integer.valueOf(ski.channel.getFDVal()), new MapEntry(ski));
return put(Integer.valueOf(ski.getFDVal()), new MapEntry(ski));
}
private MapEntry remove(SelectionKeyImpl ski) {
Integer fd = Integer.valueOf(ski.channel.getFDVal());
Integer fd = Integer.valueOf(ski.getFDVal());
MapEntry x = get(fd);
if ((x != null) && (x.ski.channel == ski.channel))
if ((x != null) && (x.ski.channel() == ski.channel()))
return remove(fd);
return null;
}
@ -114,11 +114,10 @@ class WindowsSelectorImpl extends SelectorImpl {
private final Object interruptLock = new Object();
private volatile boolean interruptTriggered;
// pending new registrations/updates, queued by implRegister and putEventOps
// pending new registrations/updates, queued by implRegister and setEventOps
private final Object updateLock = new Object();
private final Deque<SelectionKeyImpl> newKeys = new ArrayDeque<>();
private final Deque<SelectionKeyImpl> updateKeys = new ArrayDeque<>();
private final Deque<Integer> updateEvents = new ArrayDeque<>();
WindowsSelectorImpl(SelectorProvider sp) throws IOException {
@ -204,10 +203,9 @@ class WindowsSelectorImpl extends SelectorImpl {
}
// changes to interest ops
assert updateKeys.size() == updateEvents.size();
while ((ski = updateKeys.pollFirst()) != null) {
int events = updateEvents.pollFirst();
int fd = ski.channel.getFDVal();
int events = ski.translateInterestOps();
int fd = ski.getFDVal();
if (ski.isValid() && fdMap.containsKey(fd)) {
int index = ski.getIndex();
assert index >= 0 && index < totalChannels;
@ -408,13 +406,13 @@ class WindowsSelectorImpl extends SelectorImpl {
if (selectedKeys.contains(sk)) { // Key in selected set
if (me.clearedCount != updateCount) {
if (sk.channel.translateAndSetReadyOps(rOps, sk) &&
if (sk.translateAndSetReadyOps(rOps) &&
(me.updateCount != updateCount)) {
me.updateCount = updateCount;
numKeysUpdated++;
}
} else { // The readyOps have been set; now add
if (sk.channel.translateAndUpdateReadyOps(rOps, sk) &&
if (sk.translateAndUpdateReadyOps(rOps) &&
(me.updateCount != updateCount)) {
me.updateCount = updateCount;
numKeysUpdated++;
@ -423,14 +421,14 @@ class WindowsSelectorImpl extends SelectorImpl {
me.clearedCount = updateCount;
} else { // Key is not in selected set yet
if (me.clearedCount != updateCount) {
sk.channel.translateAndSetReadyOps(rOps, sk);
sk.translateAndSetReadyOps(rOps);
if ((sk.nioReadyOps() & sk.nioInterestOps()) != 0) {
selectedKeys.add(sk);
me.updateCount = updateCount;
numKeysUpdated++;
}
} else { // The readyOps have been set; now add
sk.channel.translateAndUpdateReadyOps(rOps, sk);
sk.translateAndUpdateReadyOps(rOps);
if ((sk.nioReadyOps() & sk.nioInterestOps()) != 0) {
selectedKeys.add(sk);
me.updateCount = updateCount;
@ -613,10 +611,9 @@ class WindowsSelectorImpl extends SelectorImpl {
}
@Override
public void putEventOps(SelectionKeyImpl ski, int events) {
public void setEventOps(SelectionKeyImpl ski) {
ensureOpen();
synchronized (updateLock) {
updateEvents.addLast(events); // events first in case adding key fails
updateKeys.addLast(ski);
}
}