jdk/src/java.base/macosx/classes/sun/nio/ch/KQueueArrayWrapper.java
author redestad
Thu, 21 Apr 2016 13:39:53 +0200
changeset 37593 824750ada3d6
parent 36966 4209c9e19c45
child 37781 71ed5645f17c
permissions -rw-r--r--
8154231: Simplify access to System properties from JDK code Reviewed-by: rriggs, chegar, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 22604
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
12438
c1183d4a80d4 7143744: (se) Stabilize KQueue SelectorProvider and make default on MacOSX
alanb
parents: 12047
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
c1183d4a80d4 7143744: (se) Stabilize KQueue SelectorProvider and make default on MacOSX
alanb
parents: 12047
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
c1183d4a80d4 7143744: (se) Stabilize KQueue SelectorProvider and make default on MacOSX
alanb
parents: 12047
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
 * KQueueArrayWrapper.java
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
 * Implementation of Selector using FreeBSD / Mac OS X kqueues
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
 * Derived from Sun's DevPollArrayWrapper
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
package sun.nio.ch;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
import java.io.IOException;
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
    35
import java.util.Iterator;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
    36
import java.util.LinkedList;
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36966
diff changeset
    37
import sun.security.action.GetPropertyAction;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
 * struct kevent {           // 32-bit    64-bit
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
 *     uintptr_t ident;      //   4         8
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
 *     short     filter;     //   2         2
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
 *     u_short   flags;      //   2         2
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
 *     u_int     fflags;     //   4         4
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
 *     intptr_t  data;       //   4         8
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
 *     void      *udata;     //   4         8
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
 * }                  // Total:  20        32
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
 * The implementation works in 32-bit and 64-bit world. We do this by calling a
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
 * native function that actually sets the sizes and offsets of the fields based
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
 * on which mode we're in.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
class KQueueArrayWrapper {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
    // kevent filters
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    static short EVFILT_READ;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    static short EVFILT_WRITE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
    // kevent struct
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    // These fields are now set by initStructSizes in the static initializer.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    static short SIZEOF_KEVENT;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
    static short FD_OFFSET;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    static short FILTER_OFFSET;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
12438
c1183d4a80d4 7143744: (se) Stabilize KQueue SelectorProvider and make default on MacOSX
alanb
parents: 12047
diff changeset
    65
    // kevent array size
c1183d4a80d4 7143744: (se) Stabilize KQueue SelectorProvider and make default on MacOSX
alanb
parents: 12047
diff changeset
    66
    static final int NUM_KEVENTS = 128;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    // Are we in a 64-bit VM?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    static boolean is64bit = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    // The kevent array (used for outcoming events only)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
    private AllocatedNativeObject keventArray = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    private long keventArrayAddress;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    // The kqueue fd
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
    private int kq = -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    // The fd of the interrupt line going out
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
    private int outgoingInterruptFD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    // The fd of the interrupt line coming in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    private int incomingInterruptFD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    static {
19607
bee007586d06 8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents: 14342
diff changeset
    85
        IOUtil.load();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
        initStructSizes();
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36966
diff changeset
    87
        String datamodel = GetPropertyAction.getProperty("sun.arch.data.model");
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 36966
diff changeset
    88
        is64bit = "64".equals(datamodel);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    KQueueArrayWrapper() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
        int allocationSize = SIZEOF_KEVENT * NUM_KEVENTS;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
        keventArray = new AllocatedNativeObject(allocationSize, true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
        keventArrayAddress = keventArray.address();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
        kq = init();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
    98
    // Used to update file description registrations
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
    99
    private static class Update {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   100
        SelChImpl channel;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   101
        int events;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   102
        Update(SelChImpl channel, int events) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   103
            this.channel = channel;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   104
            this.events = events;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   105
        }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   106
    }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   107
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   108
    private LinkedList<Update> updateList = new LinkedList<Update>();
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   109
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    void initInterrupt(int fd0, int fd1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        outgoingInterruptFD = fd1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
        incomingInterruptFD = fd0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
        register0(kq, fd0, 1, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    int getReventOps(int index) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
        int result = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
        int offset = SIZEOF_KEVENT*index + FILTER_OFFSET;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
        short filter = keventArray.getShort(offset);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
        // This is all that's necessary based on inspection of usage:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
        //   SinkChannelImpl, SourceChannelImpl, DatagramChannelImpl,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
        //   ServerSocketChannelImpl, SocketChannelImpl
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
        if (filter == EVFILT_READ) {
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   125
            result |= Net.POLLIN;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        } else if (filter == EVFILT_WRITE) {
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   127
            result |= Net.POLLOUT;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
        return result;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    int getDescriptor(int index) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
        int offset = SIZEOF_KEVENT*index + FD_OFFSET;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
        /* The ident field is 8 bytes in 64-bit world, however the API wants us
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
         * to return an int. Hence read the 8 bytes but return as an int.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
        if (is64bit) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
          long fd = keventArray.getLong(offset);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
          assert fd <= Integer.MAX_VALUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
          return (int) fd;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
          return keventArray.getInt(offset);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   147
    void setInterest(SelChImpl channel, int events) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   148
        synchronized (updateList) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   149
            // update existing registration
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   150
            updateList.add(new Update(channel, events));
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   151
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   154
    void release(SelChImpl channel) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   155
        synchronized (updateList) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   156
            // flush any pending updates
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   157
            for (Iterator<Update> it = updateList.iterator(); it.hasNext();) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   158
                if (it.next().channel == channel) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   159
                    it.remove();
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   160
                }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   161
            }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   162
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   163
            // remove
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   164
            register0(kq, channel.getFDVal(), 0, 0);
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   165
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   168
    void updateRegistrations() {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   169
        synchronized (updateList) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   170
            Update u = null;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   171
            while ((u = updateList.poll()) != null) {
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   172
                SelChImpl ch = u.channel;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   173
                if (!ch.isOpen())
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   174
                    continue;
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   175
22604
9b394795e216 8031997: PPC64: Make the various POLL constants system dependant
simonis
parents: 19607
diff changeset
   176
                register0(kq, ch.getFDVal(), u.events & Net.POLLIN, u.events & Net.POLLOUT);
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   177
            }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   178
        }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   179
    }
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   180
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   181
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
    void close() throws IOException {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
        if (keventArray != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
            keventArray.free();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
            keventArray = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        if (kq >= 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
            FileDispatcherImpl.closeIntFD(kq);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
            kq = -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    int poll(long timeout) {
13585
4e446fa0c1c0 7191587: (se) SelectionKey.interestOps does not defer changing the interest set to the next select [macosx]
alanb
parents: 12438
diff changeset
   194
        updateRegistrations();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
        int updated = kevent0(kq, keventArrayAddress, NUM_KEVENTS, timeout);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
        return updated;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    void interrupt() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        interrupt(outgoingInterruptFD);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    private native int init();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
    private static native void initStructSizes();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    private native void register0(int kq, int fd, int read, int write);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
    private native int kevent0(int kq, long keventAddress, int keventCount,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
                               long timeout);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
    private static native void interrupt(int fd);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
}