< prev index next >

src/java.base/share/classes/java/lang/System.java

Print this page

        

*** 54,63 **** --- 54,64 ---- import java.util.Map; import java.util.Objects; import java.util.Properties; import java.util.PropertyPermission; import java.util.ResourceBundle; + import java.util.concurrent.Callable; import java.util.function.Supplier; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; import jdk.internal.util.StaticProperty;
*** 2277,2284 **** --- 2278,2348 ---- public void loadLibrary(Class<?> caller, String library) { assert library.indexOf(java.io.File.separatorChar) < 0; ClassLoader.loadLibrary(caller, library, false); } + + public Thread currentCarrierThread() { + return Thread.currentCarrierThread(); + } + public <R> R executeOnCarrierThread(Callable<R> task) throws Exception { + Thread t = Thread.currentCarrierThread(); + Fiber<?> f = t.getFiber(); + if (f != null) t.setFiber(null); + try { + return task.call(); + } finally { + if (f != null) t.setFiber(f); + } + } + public <T> T getCarrierThreadLocal(ThreadLocal<T> local) { + return local.getCarrierThreadLocal(); + } + public Fiber<?> getFiber(Thread t) { + if (t instanceof ShadowThread) { + return ((ShadowThread) t).fiber(); + } else { + return null; + } + } + public Thread getShadowThread(Fiber<?> f) { + return f.shadowThreadOrNull(); + } + public Object currentStrand() { + Thread thread = Thread.currentCarrierThread(); + Fiber<?> fiber = thread.getFiber(); + return (fiber != null) ? fiber : thread; + } + public void interrupt(Object strand) { + if (strand instanceof Fiber) { + ((Fiber) strand).interrupt(); + } else { + ((Thread) strand).interrupt(); + } + } + public boolean isInterrupted() { + Object strand = currentStrand(); + if (strand instanceof Fiber) { + return ((Fiber) strand).isInterrupted(); + } else { + return ((Thread) strand).isInterrupted(); + } + } + public boolean clearInterrupt() { + if (currentStrand() instanceof Fiber) { + return Fiber.clearInterrupt(); + } else { + return Thread.interrupted(); + } + } + public void parkFiber() { + Fiber.park(); + } + public void parkFiber(long nanos) { + Fiber.parkNanos(nanos); + } + public void unparkFiber(Fiber<?> fiber) { + fiber.unpark(); + } }); } }
< prev index next >