< prev index next >

src/java.base/share/classes/sun/nio/ch/SelChImpl.java

Print this page

        

@@ -29,10 +29,12 @@
 import java.io.FileDescriptor;
 import java.io.IOException;
 
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 
+import jdk.internal.misc.Strands;
+
 /**
  * An interface that allows translation (and more!).
  *
  * @since 1.4
  */

@@ -69,11 +71,11 @@
     int translateInterestOps(int ops);
 
     void kill() throws IOException;
 
     /**
-     * Disables the current thread for scheduling purposes until this
+     * Disables the current thread or fiber for scheduling purposes until this
      * channel is ready for I/O, or asynchronously closed, for up to the
      * specified waiting time.
      *
      * <p> This method does <em>not</em> report which of these caused the
      * method to return. Callers should re-check the conditions which caused

@@ -81,21 +83,37 @@
      *
      * @param event the event to poll
      * @param nanos the timeout to wait; {@code <= 0} to wait indefinitely
      */
     default void park(int event, long nanos) throws IOException {
-        long millis;
-        if (nanos <= 0) {
-            millis = -1;
+        Object strand = Strands.currentStrand();
+        if (PollerProvider.available() && (strand instanceof Fiber)) {
+            Poller.register(strand, getFDVal(), event);
+            if (isOpen()) {
+                try {
+                    if (nanos == 0) {
+                        Strands.parkFiber();
+                    } else {
+                        Strands.parkFiber(nanos);
+                    }
+                } finally {
+                    Poller.deregister(strand, getFDVal(), event);
+                }
+            }
         } else {
-            millis = NANOSECONDS.toMillis(nanos);
+            long millis;
+            if (nanos == 0) {
+                millis = -1;
+            } else {
+                millis = NANOSECONDS.toMillis(nanos);
+            }
+            Net.poll(getFD(), event, millis);
         }
-        Net.poll(getFD(), event, millis);
     }
 
     /**
-     * Disables the current thread for scheduling purposes until this
+     * Disables the current thread or fiber for scheduling purposes until this
      * channel is ready for I/O, or asynchronously closed.
      *
      * <p> This method does <em>not</em> report which of these caused the
      * method to return. Callers should re-check the conditions which caused
      * the thread to park.

@@ -103,7 +121,6 @@
      * @param event the event to poll
      */
     default void park(int event) throws IOException {
         park(event, 0L);
     }
-
 }
< prev index next >