| Method from sun.nio.ch.DevPollArrayWrapper Detail: |
void clearInterrupted() {
interrupted = false;
}
|
void closeDevPollFD() throws IOException {
FileDispatcher.closeIntFD(wfd);
pollArray.free();
}
|
int getDescriptor(int i) {
int offset = SIZE_POLLFD * i + FD_OFFSET;
return pollArray.getInt(offset);
}
|
int getEventOps(int i) {
int offset = SIZE_POLLFD * i + EVENT_OFFSET;
return pollArray.getShort(offset);
}
|
int getReventOps(int i) {
int offset = SIZE_POLLFD * i + REVENT_OFFSET;
return pollArray.getShort(offset);
}
|
void initInterrupt(int fd0,
int fd1) {
outgoingInterruptFD = fd1;
incomingInterruptFD = fd0;
register(wfd, fd0, POLLIN);
}
|
public void interrupt() {
interrupt(outgoingInterruptFD);
}
|
boolean interrupted() {
return interrupted;
}
|
public int interruptedIndex() {
return interruptedIndex;
}
|
int poll(long timeout) {
updateRegistrations();
updated = poll0(pollArrayAddress, NUM_POLLFDS, timeout, wfd);
for (int i=0; i< updated; i++) {
if (getDescriptor(i) == incomingInterruptFD) {
interruptedIndex = i;
interrupted = true;
break;
}
}
return updated;
}
|
void putDescriptor(int i,
int fd) {
int offset = SIZE_POLLFD * i + FD_OFFSET;
pollArray.putInt(offset, fd);
}
|
void putEventOps(int i,
int event) {
int offset = SIZE_POLLFD * i + EVENT_OFFSET;
pollArray.putShort(offset, (short)event);
}
|
void putReventOps(int i,
int revent) {
int offset = SIZE_POLLFD * i + REVENT_OFFSET;
pollArray.putShort(offset, (short)revent);
}
|
void release(int fd) {
synchronized (updateList) {
updateList.add(new Updator(fd, POLLREMOVE));
}
}
|
void setInterest(int fd,
int mask) {
synchronized (updateList) {
updateList.add(new Updator(fd, mask));
}
}
|
void updateRegistrations() {
// take snapshot of the updateList size to see if there are
// any registrations to update
int updateSize;
synchronized (updateList) {
updateSize = updateList.size();
}
if (updateSize > 0) {
// Construct a pollfd array with updated masks; we may overallocate
// by some amount because if the events are already POLLREMOVE
// then the second pollfd of that pair will not be needed. The
// number of entries is limited to a reasonable number to avoid
// allocating a lot of memory.
int maxUpdates = Math.min(updateSize * 2, MAX_UPDATE_SIZE);
int allocationSize = maxUpdates * SIZE_POLLFD;
AllocatedNativeObject updatePollArray =
new AllocatedNativeObject(allocationSize, true);
try {
synchronized (updateList) {
while (updateList.size() > 0) {
// We have to insert a dummy node in between each
// real update to use POLLREMOVE on the fd first because
// otherwise the changes are simply OR'd together
int index = 0;
Updator u = null;
while ((u = updateList.poll()) != null) {
// First add pollfd struct to clear out this fd
putPollFD(updatePollArray, index, u.fd, POLLREMOVE);
index++;
// Now add pollfd to update this fd, if necessary
if (u.mask != POLLREMOVE) {
putPollFD(updatePollArray, index, u.fd,
(short)u.mask);
index++;
}
// Check against the max allocation size; these are
// all we will process. Valid index ranges from 0 to
// (maxUpdates - 1) and we can use up to 2 per loop
if (index > maxUpdates - 2)
break;
}
// Register the changes with /dev/poll
registerMultiple(wfd, updatePollArray.address(), index);
}
}
} finally {
// Free the native array
updatePollArray.free();
// BUG: If an exception was thrown then the selector now believes
// that the last set of changes was updated but it probably
// was not. This should not be a likely occurrence.
}
}
}
|