src/java.base/windows/classes/sun/nio/ch/WindowsSelectorImpl.java
changeset 49248 15a0e60c8b97
parent 47216 71c04702a3d5
child 49493 814bd31f8da0
equal deleted inserted replaced
49247:95e00d2708fb 49248:15a0e60c8b97
     1 /*
     1 /*
     2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    46  *
    46  *
    47  * @author Konstantin Kladko
    47  * @author Konstantin Kladko
    48  * @author Mark Reinhold
    48  * @author Mark Reinhold
    49  */
    49  */
    50 
    50 
    51 final class WindowsSelectorImpl extends SelectorImpl {
    51 class WindowsSelectorImpl extends SelectorImpl {
    52     // Initial capacity of the poll array
    52     // Initial capacity of the poll array
    53     private final int INIT_CAP = 8;
    53     private final int INIT_CAP = 8;
    54     // Maximum number of sockets for select().
    54     // Maximum number of sockets for select().
    55     // Should be INIT_CAP times a power of 2
    55     // Should be INIT_CAP times a power of 2
    56     private static final int MAX_SELECTABLE_FDS = 1024;
    56     private static final int MAX_SELECTABLE_FDS = 1024;
    79 
    79 
    80     // File descriptors corresponding to source and sink
    80     // File descriptors corresponding to source and sink
    81     private final int wakeupSourceFd, wakeupSinkFd;
    81     private final int wakeupSourceFd, wakeupSinkFd;
    82 
    82 
    83     // Lock for close cleanup
    83     // Lock for close cleanup
    84     private Object closeLock = new Object();
    84     private final Object closeLock = new Object();
    85 
    85 
    86     // Maps file descriptors to their indices in  pollArray
    86     // Maps file descriptors to their indices in  pollArray
    87     private static final class FdMap extends HashMap<Integer, MapEntry> {
    87     private static final class FdMap extends HashMap<Integer, MapEntry> {
    88         static final long serialVersionUID = 0L;
    88         static final long serialVersionUID = 0L;
    89         private MapEntry get(int desc) {
    89         private MapEntry get(int desc) {
   133         wakeupSinkFd = ((SelChImpl)sink).getFDVal();
   133         wakeupSinkFd = ((SelChImpl)sink).getFDVal();
   134 
   134 
   135         pollWrapper.addWakeupSocket(wakeupSourceFd, 0);
   135         pollWrapper.addWakeupSocket(wakeupSourceFd, 0);
   136     }
   136     }
   137 
   137 
       
   138     @Override
   138     protected int doSelect(long timeout) throws IOException {
   139     protected int doSelect(long timeout) throws IOException {
   139         if (channelArray == null)
   140         if (channelArray == null)
   140             throw new ClosedSelectorException();
   141             throw new ClosedSelectorException();
   141         this.timeout = timeout; // set selector timeout
   142         this.timeout = timeout; // set selector timeout
   142         processDeregisterQueue();
   143         processDeregisterQueue();
   498             numKeysUpdated += t.subSelector.processSelectedKeys(updateCount);
   499             numKeysUpdated += t.subSelector.processSelectedKeys(updateCount);
   499         }
   500         }
   500         return numKeysUpdated;
   501         return numKeysUpdated;
   501     }
   502     }
   502 
   503 
       
   504     @Override
   503     protected void implClose() throws IOException {
   505     protected void implClose() throws IOException {
   504         synchronized (closeLock) {
   506         synchronized (closeLock) {
   505             if (channelArray != null) {
   507             if (channelArray != null) {
   506                 if (pollWrapper != null) {
   508                 if (pollWrapper != null) {
   507                     // prevent further wakeup
   509                     // prevent further wakeup
   518                                 ((SelChImpl)selch).kill();
   520                                 ((SelChImpl)selch).kill();
   519                         }
   521                         }
   520                     }
   522                     }
   521                     pollWrapper.free();
   523                     pollWrapper.free();
   522                     pollWrapper = null;
   524                     pollWrapper = null;
   523                     selectedKeys = null;
       
   524                     channelArray = null;
   525                     channelArray = null;
   525                     // Make all remaining helper threads exit
   526                     // Make all remaining helper threads exit
   526                     for (SelectThread t: threads)
   527                     for (SelectThread t: threads)
   527                          t.makeZombie();
   528                          t.makeZombie();
   528                     startLock.startThreads();
   529                     startLock.startThreads();