< prev index next >

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

Print this page
@@ -26,11 +26,11 @@
  package sun.nio.ch;
  
  import java.nio.channels.Channel;
  import java.io.FileDescriptor;
  import java.io.IOException;
- 
+ import jdk.internal.misc.VirtualThreads;
  import static java.util.concurrent.TimeUnit.NANOSECONDS;
  
  /**
   * An interface that allows translation (and more!).
   *

@@ -69,11 +69,11 @@
      int translateInterestOps(int ops);
  
      void kill() throws IOException;
  
      /**
-      * Disables the current thread for scheduling purposes until this
+      * Disables the current thread  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,17 +81,32 @@
       *
       * @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;
+         if (Thread.currentThread().isVirtual()) {
+             Poller.register(getFDVal(), event);
+             try {
+                 if (isOpen()) {
+                     if (nanos == 0) {
+                         VirtualThreads.park();
+                     } else {
+                         VirtualThreads.park(nanos);
+                     }
+                 }
+             } finally {
+                 Poller.deregister(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
       * channel is ready for I/O, or asynchronously closed.

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