< prev index next >

src/java.base/windows/classes/sun/nio/ch/NativeThread.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -26,17 +26,39 @@
  package sun.nio.ch;
  
  
  // Signalling operations on native threads
  
+ public class NativeThread {
+     private static final long VIRTUAL_THREAD_ID = -1L;
  
- class NativeThread {
+     /**
+      * Returns a token representing the current thread or -1 if called in the
+      * context of a virtual thread
+      */
+     public static long current() {
+         if (Thread.currentThread().isVirtual()) {
+             return VIRTUAL_THREAD_ID;
+         } else {
+             return 0;
+         }
+     }
  
-     static long current() {
-         // return 0 to ensure that async close of blocking sockets will close
-         // the underlying socket.
+     static long currentKernelThread() {
          return 0;
      }
  
-     static void signal(long nt) { }
+     static void signal(long tid) {
+         throw new UnsupportedOperationException();
+     }
  
+     /**
+      * Returns true if the token presents a virtual thread
+      */
+     static boolean isVirtualThread(long tid) {
+         return (tid == VIRTUAL_THREAD_ID);
+     }
+ 
+     static boolean isKernelThread(long tid) {
+         return false;
+     }
  }
< prev index next >