< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java

Print this page
rev 50306 : imported patch loom-fibers

*** 33,42 **** --- 33,43 ---- * 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,166 **** * * @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) U.unpark(thread); } /** * Disables the current thread for thread scheduling purposes unless the * permit is available. * --- 155,172 ---- * * @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 instanceof Fiber) { ! ((Fiber)thread).unpark(); ! } else { U.unpark(thread); } + } + } /** * Disables the current thread for thread scheduling purposes unless the * permit is available. *
*** 189,199 **** --- 195,209 ---- * @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,239 **** --- 239,253 ---- */ 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,280 **** --- 284,300 ---- * @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,329 **** --- 338,354 ---- * 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,363 **** * upon return. * * @param nanos the maximum number of nanoseconds to wait */ public static void parkNanos(long nanos) { ! if (nanos > 0) U.park(false, nanos); } /** * Disables the current thread for thread scheduling purposes, until * the specified deadline, unless the permit is available. * --- 376,394 ---- * upon return. * * @param nanos the maximum number of nanoseconds to wait */ public static void parkNanos(long nanos) { ! 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,397 **** --- 417,435 ---- * * @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 >