< prev index next > src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java
Print this page
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util.concurrent.locks;
! import jdk.internal.misc.VirtualThreads;
import jdk.internal.misc.Unsafe;
/**
* Basic thread blocking primitives for creating locks and other
* synchronization classes.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util.concurrent.locks;
! import java.util.concurrent.TimeUnit;
+ import jdk.internal.access.JavaLangAccess;
+ import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe;
/**
* Basic thread blocking primitives for creating locks and other
* synchronization classes.
* this operation has no effect
*/
public static void unpark(Thread thread) {
if (thread != null) {
if (thread.isVirtual()) {
! VirtualThreads.unpark(thread);
} else {
U.unpark(thread);
}
}
}
* this operation has no effect
*/
public static void unpark(Thread thread) {
if (thread != null) {
if (thread.isVirtual()) {
! JLA.unparkVirtualThread(thread);
} else {
U.unpark(thread);
}
}
}
public static void park(Object blocker) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
try {
if (t.isVirtual()) {
! VirtualThreads.park();
} else {
U.park(false, 0L);
}
} finally {
setBlocker(t, null);
public static void park(Object blocker) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
try {
if (t.isVirtual()) {
! JLA.parkVirtualThread();
} else {
U.park(false, 0L);
}
} finally {
setBlocker(t, null);
if (nanos > 0) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
try {
if (t.isVirtual()) {
! VirtualThreads.park(nanos);
} else {
U.park(false, nanos);
}
} finally {
setBlocker(t, null);
if (nanos > 0) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
try {
if (t.isVirtual()) {
! JLA.parkVirtualThread(nanos);
} else {
U.park(false, nanos);
}
} finally {
setBlocker(t, null);
*/
public static void parkUntil(Object blocker, long deadline) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
try {
! if (t.isVirtual()) {
- VirtualThreads.parkUntil(deadline);
- } else {
- U.park(true, deadline);
- }
} finally {
setBlocker(t, null);
}
}
*/
public static void parkUntil(Object blocker, long deadline) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
try {
! parkUntil(deadline);
} finally {
setBlocker(t, null);
}
}
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread upon return.
*/
public static void park() {
if (Thread.currentThread().isVirtual()) {
! VirtualThreads.park();
} else {
U.park(false, 0L);
}
}
* the thread to park in the first place. Callers may also determine,
* for example, the interrupt status of the thread upon return.
*/
public static void park() {
if (Thread.currentThread().isVirtual()) {
! JLA.parkVirtualThread();
} else {
U.park(false, 0L);
}
}
* @param nanos the maximum number of nanoseconds to wait
*/
public static void parkNanos(long nanos) {
if (nanos > 0) {
if (Thread.currentThread().isVirtual()) {
! VirtualThreads.park(nanos);
} else {
U.park(false, nanos);
}
}
}
* @param nanos the maximum number of nanoseconds to wait
*/
public static void parkNanos(long nanos) {
if (nanos > 0) {
if (Thread.currentThread().isVirtual()) {
! JLA.parkVirtualThread(nanos);
} else {
U.park(false, nanos);
}
}
}
* @param deadline the absolute time, in milliseconds from the Epoch,
* to wait until
*/
public static void parkUntil(long deadline) {
if (Thread.currentThread().isVirtual()) {
! VirtualThreads.parkUntil(deadline);
} else {
U.park(true, deadline);
}
}
* @param deadline the absolute time, in milliseconds from the Epoch,
* to wait until
*/
public static void parkUntil(long deadline) {
if (Thread.currentThread().isVirtual()) {
! long millis = deadline - System.currentTimeMillis();
+ JLA.parkVirtualThread(TimeUnit.MILLISECONDS.toNanos(millis));
} else {
U.park(true, deadline);
}
}
// Hotspot implementation via intrinsics API
private static final Unsafe U = Unsafe.getUnsafe();
private static final long PARKBLOCKER
= U.objectFieldOffset(Thread.class, "parkBlocker");
+ private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
}
< prev index next >