125 |
125 |
126 // Used by release and updateRegistrations to track whether a file |
126 // Used by release and updateRegistrations to track whether a file |
127 // descriptor is registered with /dev/poll. |
127 // descriptor is registered with /dev/poll. |
128 private final BitSet registered = new BitSet(); |
128 private final BitSet registered = new BitSet(); |
129 |
129 |
130 DevPollArrayWrapper() { |
130 DevPollArrayWrapper() throws IOException { |
131 int allocationSize = NUM_POLLFDS * SIZE_POLLFD; |
131 int allocationSize = NUM_POLLFDS * SIZE_POLLFD; |
132 pollArray = new AllocatedNativeObject(allocationSize, true); |
132 pollArray = new AllocatedNativeObject(allocationSize, true); |
133 pollArrayAddress = pollArray.address(); |
133 pollArrayAddress = pollArray.address(); |
134 wfd = init(); |
134 wfd = init(); |
135 if (OPEN_MAX > MAX_UPDATE_ARRAY_SIZE) |
135 if (OPEN_MAX > MAX_UPDATE_ARRAY_SIZE) |
136 eventsHigh = new HashMap<>(); |
136 eventsHigh = new HashMap<>(); |
137 } |
137 } |
138 |
138 |
139 void initInterrupt(int fd0, int fd1) { |
139 void initInterrupt(int fd0, int fd1) throws IOException { |
140 outgoingInterruptFD = fd1; |
140 outgoingInterruptFD = fd1; |
141 incomingInterruptFD = fd0; |
141 incomingInterruptFD = fd0; |
142 register(wfd, fd0, POLLIN); |
142 register(wfd, fd0, POLLIN); |
143 } |
143 } |
144 |
144 |
198 assert (b == mask) && (b != IGNORE); |
198 assert (b == mask) && (b != IGNORE); |
199 setUpdateEvents(fd, b); |
199 setUpdateEvents(fd, b); |
200 } |
200 } |
201 } |
201 } |
202 |
202 |
203 void release(int fd) { |
203 void release(int fd) throws IOException { |
204 synchronized (updateLock) { |
204 synchronized (updateLock) { |
205 // ignore any pending update for this file descriptor |
205 // ignore any pending update for this file descriptor |
206 setUpdateEvents(fd, IGNORE); |
206 setUpdateEvents(fd, IGNORE); |
207 |
207 |
208 // remove from /dev/poll |
208 // remove from /dev/poll |
295 } |
295 } |
296 |
296 |
297 boolean interrupted = false; |
297 boolean interrupted = false; |
298 |
298 |
299 public void interrupt() { |
299 public void interrupt() { |
300 interrupt(outgoingInterruptFD); |
300 try { |
|
301 IOUtil.write1(outgoingInterruptFD, (byte)0); |
|
302 } catch (IOException ioe) { |
|
303 throw new InternalError(ioe); |
|
304 } |
301 } |
305 } |
302 |
306 |
303 public int interruptedIndex() { |
307 public int interruptedIndex() { |
304 return interruptedIndex; |
308 return interruptedIndex; |
305 } |
309 } |
310 |
314 |
311 void clearInterrupted() { |
315 void clearInterrupted() { |
312 interrupted = false; |
316 interrupted = false; |
313 } |
317 } |
314 |
318 |
315 private native int init(); |
319 private native int init() throws IOException; |
316 private native void register(int wfd, int fd, int mask); |
320 private native void register(int wfd, int fd, int mask) throws IOException; |
317 private native void registerMultiple(int wfd, long address, int len) |
321 private native void registerMultiple(int wfd, long address, int len) |
318 throws IOException; |
322 throws IOException; |
319 private native int poll0(long pollAddress, int numfds, long timeout, |
323 private native int poll0(long pollAddress, int numfds, long timeout, int wfd) |
320 int wfd); |
324 throws IOException; |
321 private static native void interrupt(int fd); |
|
322 |
325 |
323 static { |
326 static { |
324 IOUtil.load(); |
327 IOUtil.load(); |
325 } |
328 } |
326 } |
329 } |