< prev index next >
src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java
Print this page
rev 50306 : imported patch loom-fibers
@@ -33,10 +33,11 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util.concurrent.locks;
+import java.util.concurrent.TimeUnit;
import jdk.internal.misc.Unsafe;
/**
* Basic thread blocking primitives for creating locks and other
* synchronization classes.
@@ -154,13 +155,18 @@
*
* @param thread the thread to unpark, or {@code null}, in which case
* this operation has no effect
*/
public static void unpark(Thread thread) {
- if (thread != null)
+ if (thread != null) {
+ if (thread instanceof Fiber) {
+ ((Fiber)thread).unpark();
+ } else {
U.unpark(thread);
}
+ }
+ }
/**
* Disables the current thread for thread scheduling purposes unless the
* permit is available.
*
@@ -189,11 +195,15 @@
* @since 1.6
*/
public static void park(Object blocker) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
+ if (t instanceof Fiber) {
+ Fiber.park();
+ } else {
U.park(false, 0L);
+ }
setBlocker(t, null);
}
/**
* Disables the current thread for thread scheduling purposes, for up to
@@ -229,11 +239,15 @@
*/
public static void parkNanos(Object blocker, long nanos) {
if (nanos > 0) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
+ if (t instanceof Fiber) {
+ Fiber.parkNanos(nanos);
+ } else {
U.park(false, nanos);
+ }
setBlocker(t, null);
}
}
/**
@@ -270,11 +284,17 @@
* @since 1.6
*/
public static void parkUntil(Object blocker, long deadline) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
+ if (t instanceof Fiber) {
+ long millis = deadline - System.currentTimeMillis();
+ long nanos = TimeUnit.NANOSECONDS.convert(millis, TimeUnit.MILLISECONDS);
+ Fiber.parkNanos(nanos);
+ } else {
U.park(true, deadline);
+ }
setBlocker(t, null);
}
/**
* Returns the blocker object supplied to the most recent
@@ -318,12 +338,17 @@
* method to return. Callers should re-check the conditions which caused
* 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() {
+ Thread t = Thread.currentThread();
+ if (t instanceof Fiber) {
+ Fiber.park();
+ } else {
U.park(false, 0L);
}
+ }
/**
* Disables the current thread for thread scheduling purposes, for up to
* the specified waiting time, unless the permit is available.
*
@@ -351,13 +376,19 @@
* upon return.
*
* @param nanos the maximum number of nanoseconds to wait
*/
public static void parkNanos(long nanos) {
- if (nanos > 0)
+ if (nanos > 0) {
+ Thread t = Thread.currentThread();
+ if (t instanceof Fiber) {
+ Fiber.parkNanos(nanos);
+ } else {
U.park(false, nanos);
}
+ }
+ }
/**
* Disables the current thread for thread scheduling purposes, until
* the specified deadline, unless the permit is available.
*
@@ -386,12 +417,19 @@
*
* @param deadline the absolute time, in milliseconds from the Epoch,
* to wait until
*/
public static void parkUntil(long deadline) {
+ Thread t = Thread.currentThread();
+ if (t instanceof Fiber) {
+ long millis = deadline - System.currentTimeMillis();
+ long nanos = TimeUnit.NANOSECONDS.convert(millis, TimeUnit.MILLISECONDS);
+ Fiber.parkNanos(nanos);
+ } else {
U.park(true, deadline);
}
+ }
/**
* Returns the pseudo-randomly initialized or updated secondary seed.
* Copied from ThreadLocalRandom due to package access restrictions.
*/
< prev index next >