mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 03:24:38 +02:00
8199791: (se) More Selector cleanup
Reviewed-by: redestad, bpb
This commit is contained in:
parent
de23920e05
commit
3bb85f5fc5
33 changed files with 754 additions and 1516 deletions
|
@ -127,7 +127,7 @@ class DevPollArrayWrapper {
|
|||
// descriptor is registered with /dev/poll.
|
||||
private final BitSet registered = new BitSet();
|
||||
|
||||
DevPollArrayWrapper() {
|
||||
DevPollArrayWrapper() throws IOException {
|
||||
int allocationSize = NUM_POLLFDS * SIZE_POLLFD;
|
||||
pollArray = new AllocatedNativeObject(allocationSize, true);
|
||||
pollArrayAddress = pollArray.address();
|
||||
|
@ -136,7 +136,7 @@ class DevPollArrayWrapper {
|
|||
eventsHigh = new HashMap<>();
|
||||
}
|
||||
|
||||
void initInterrupt(int fd0, int fd1) {
|
||||
void initInterrupt(int fd0, int fd1) throws IOException {
|
||||
outgoingInterruptFD = fd1;
|
||||
incomingInterruptFD = fd0;
|
||||
register(wfd, fd0, POLLIN);
|
||||
|
@ -200,7 +200,7 @@ class DevPollArrayWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
void release(int fd) {
|
||||
void release(int fd) throws IOException {
|
||||
synchronized (updateLock) {
|
||||
// ignore any pending update for this file descriptor
|
||||
setUpdateEvents(fd, IGNORE);
|
||||
|
@ -297,7 +297,11 @@ class DevPollArrayWrapper {
|
|||
boolean interrupted = false;
|
||||
|
||||
public void interrupt() {
|
||||
interrupt(outgoingInterruptFD);
|
||||
try {
|
||||
IOUtil.write1(outgoingInterruptFD, (byte)0);
|
||||
} catch (IOException ioe) {
|
||||
throw new InternalError(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
public int interruptedIndex() {
|
||||
|
@ -312,13 +316,12 @@ class DevPollArrayWrapper {
|
|||
interrupted = false;
|
||||
}
|
||||
|
||||
private native int init();
|
||||
private native void register(int wfd, int fd, int mask);
|
||||
private native int init() throws IOException;
|
||||
private native void register(int wfd, int fd, int mask) throws IOException;
|
||||
private native void registerMultiple(int wfd, long address, int len)
|
||||
throws IOException;
|
||||
private native int poll0(long pollAddress, int numfds, long timeout,
|
||||
int wfd);
|
||||
private static native void interrupt(int fd);
|
||||
private native int poll0(long pollAddress, int numfds, long timeout, int wfd)
|
||||
throws IOException;
|
||||
|
||||
static {
|
||||
IOUtil.load();
|
||||
|
|
|
@ -61,7 +61,7 @@ class DevPollSelectorImpl
|
|||
* Package private constructor called by factory method in
|
||||
* the abstract superclass Selector.
|
||||
*/
|
||||
DevPollSelectorImpl(SelectorProvider sp) {
|
||||
DevPollSelectorImpl(SelectorProvider sp) throws IOException {
|
||||
super(sp);
|
||||
long pipeFds = IOUtil.makePipe(false);
|
||||
fd0 = (int) (pipeFds >>> 32);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 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
|
||||
|
@ -181,12 +181,26 @@ class EventPortWrapper {
|
|||
}
|
||||
|
||||
// poll for events
|
||||
int updated = port_getn(pfd, pollArrayAddress, POLL_MAX, timeout);
|
||||
int numEntries;
|
||||
long to = timeout;
|
||||
boolean timedPoll = (to > 0);
|
||||
do {
|
||||
long startTime = timedPoll ? System.currentTimeMillis() : 0;
|
||||
numEntries = port_getn(pfd, pollArrayAddress, POLL_MAX, timeout);
|
||||
if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
|
||||
// timed poll interrupted so need to adjust timeout
|
||||
to -= System.currentTimeMillis() - startTime;
|
||||
if (to <= 0) {
|
||||
// timeout also expired so no retry
|
||||
numEntries = 0;
|
||||
}
|
||||
}
|
||||
} while (numEntries == IOStatus.INTERRUPTED);
|
||||
|
||||
// after polling we need to queue all polled file descriptors as they
|
||||
// are candidates to register for the next poll.
|
||||
synchronized (updateLock) {
|
||||
for (int i=0; i<updated; i++) {
|
||||
for (int i=0; i<numEntries; i++) {
|
||||
if (getSource(i) == PORT_SOURCE_USER) {
|
||||
interrupted = true;
|
||||
setDescriptor(i, -1);
|
||||
|
@ -199,7 +213,7 @@ class EventPortWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
return updated;
|
||||
return numEntries;
|
||||
}
|
||||
|
||||
private void setInterest(int fd) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -164,7 +164,10 @@ class SolarisEventPort
|
|||
// A error here is fatal (thread will not be replaced)
|
||||
replaceMe = false;
|
||||
try {
|
||||
port_get(port, address);
|
||||
int n;
|
||||
do {
|
||||
n = port_get(port, address);
|
||||
} while (n == IOStatus.INTERRUPTED);
|
||||
} catch (IOException x) {
|
||||
x.printStackTrace();
|
||||
return;
|
||||
|
@ -240,7 +243,7 @@ class SolarisEventPort
|
|||
/**
|
||||
* Retrieves a single event from a port
|
||||
*/
|
||||
static native void port_get(int port, long pe) throws IOException;
|
||||
static native int port_get(int port, long address) throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves at most {@code max} events from a port.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue