< prev index next >

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

Print this page

 35 // that can be used to release a native thread from a blocking I/O operation.
 36 // On systems that do not require this type of signalling, the current() method
 37 // always returns -1 and the signal(long) method has no effect.
 38 
 39 public class NativeThread {
 40     private static final long VIRTUAL_THREAD_ID = -1L;
 41 
 42     /**
 43      * Returns the id of the current native thread if the platform can signal
 44      * native threads, 0 if the platform can not signal native threads, or
 45      * -1L if the current thread is a virtual thread.
 46      */
 47     public static long current() {
 48         if (Thread.currentThread().isVirtual()) {
 49             return VIRTUAL_THREAD_ID;
 50         } else {
 51             return current0();
 52         }
 53     }
 54 
 55     /**
 56      * Returns the id of the current native thread if the platform can signal
 57      * native threads, 0 if the platform can not signal native threads.
 58      */
 59     static long currentNativeThread() {
 60         return current0();
 61     }
 62 
 63     /**
 64      * Signals the given native thread.
 65      *
 66      * @throws IllegalArgumentException if tid is not a token to a native thread
 67      */
 68     public static void signal(long tid) {
 69         if (tid == 0 || tid == VIRTUAL_THREAD_ID)
 70             throw new IllegalArgumentException();
 71         signal0(tid);
 72     }
 73 
 74     /**
 75      * Returns true the tid is the id of a native thread.
 76      */
 77     static boolean isNativeThread(long tid) {
 78         return (tid != 0 && tid != VIRTUAL_THREAD_ID);
 79     }
 80 
 81     /**
 82      * Returns true if tid is -1L.

 35 // that can be used to release a native thread from a blocking I/O operation.
 36 // On systems that do not require this type of signalling, the current() method
 37 // always returns -1 and the signal(long) method has no effect.
 38 
 39 public class NativeThread {
 40     private static final long VIRTUAL_THREAD_ID = -1L;
 41 
 42     /**
 43      * Returns the id of the current native thread if the platform can signal
 44      * native threads, 0 if the platform can not signal native threads, or
 45      * -1L if the current thread is a virtual thread.
 46      */
 47     public static long current() {
 48         if (Thread.currentThread().isVirtual()) {
 49             return VIRTUAL_THREAD_ID;
 50         } else {
 51             return current0();
 52         }
 53     }
 54 








 55     /**
 56      * Signals the given native thread.
 57      *
 58      * @throws IllegalArgumentException if tid is not a token to a native thread
 59      */
 60     public static void signal(long tid) {
 61         if (tid == 0 || tid == VIRTUAL_THREAD_ID)
 62             throw new IllegalArgumentException();
 63         signal0(tid);
 64     }
 65 
 66     /**
 67      * Returns true the tid is the id of a native thread.
 68      */
 69     static boolean isNativeThread(long tid) {
 70         return (tid != 0 && tid != VIRTUAL_THREAD_ID);
 71     }
 72 
 73     /**
 74      * Returns true if tid is -1L.
< prev index next >