< prev index next >

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

Print this page
*** 26,11 ***
  package sun.nio.ch;
  
  import java.nio.channels.Channel;
  import java.io.FileDescriptor;
  import java.io.IOException;
! 
  import static java.util.concurrent.TimeUnit.NANOSECONDS;
  
  /**
   * An interface that allows translation (and more!).
   *
--- 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 ***
      int translateInterestOps(int ops);
  
      void kill() throws IOException;
  
      /**
!      * 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
--- 69,11 ---
      int translateInterestOps(int ops);
  
      void kill() throws IOException;
  
      /**
!      * 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 ***
       *
       * @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;
          } else {
!             millis = NANOSECONDS.toMillis(nanos);
          }
-         Net.poll(getFD(), event, millis);
      }
  
      /**
       * Disables the current thread for scheduling purposes until this
       * channel is ready for I/O, or asynchronously closed.
--- 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 {
!         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 {
!             long millis;
+             if (nanos == 0) {
+                 millis = -1;
+             } else {
+                 millis = NANOSECONDS.toMillis(nanos);
+             }
+             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 ***
       * @param event the event to poll
       */
      default void park(int event) throws IOException {
          park(event, 0L);
      }
- 
  }
--- 118,6 ---
< prev index next >