diff --git a/classpath/java/util/concurrent/locks/Condition.java b/classpath/java/util/concurrent/locks/Condition.java new file mode 100644 index 0000000000..7a021eb289 --- /dev/null +++ b/classpath/java/util/concurrent/locks/Condition.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2008-2014, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.util.concurrent.locks; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +public interface Condition { + public void await(); + public boolean await(long time, TimeUnit unit); + public long awaitNanos(long nanosTimeout); + public void awaitUninterruptibly(); + public boolean awaitUntil(Date deadline); + public void signal(); + public void signalAll(); +} diff --git a/classpath/java/util/concurrent/locks/Lock.java b/classpath/java/util/concurrent/locks/Lock.java new file mode 100644 index 0000000000..f2fb9b0792 --- /dev/null +++ b/classpath/java/util/concurrent/locks/Lock.java @@ -0,0 +1,22 @@ +/* Copyright (c) 2008-2014, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.util.concurrent.locks; + +import java.util.concurrent.TimeUnit; + +public interface Lock { + public void lock(); + public void lockInterruptibly() throws InterruptedException; + public Condition newCondition(); + public boolean tryLock(); + public boolean tryLock(long time, TimeUnit unit) throws InterruptedException; + public void unlock(); +} diff --git a/classpath/java/util/concurrent/locks/LockSupport.java b/classpath/java/util/concurrent/locks/LockSupport.java new file mode 100644 index 0000000000..1f547c465d --- /dev/null +++ b/classpath/java/util/concurrent/locks/LockSupport.java @@ -0,0 +1,89 @@ +/* Copyright (c) 2008-2014, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.util.concurrent.locks; + +import sun.misc.Unsafe; + +public class LockSupport { + private LockSupport() { + // can't construct + } + + private static final Unsafe unsafe; + private static final long parkBlockerOffset; + + static { + unsafe = Unsafe.getUnsafe(); + try { + parkBlockerOffset = unsafe.objectFieldOffset(java.lang.Thread.class.getDeclaredField("parkBlocker")); + } catch (Exception ex) { + throw new Error(ex); + } + } + + private static void setBlocker(Thread t, Object arg) { + unsafe.putObject(t, parkBlockerOffset, arg); + } + + public static void unpark(Thread thread) { + if (thread != null) { + unsafe.unpark(thread); + } + } + + public static void park(Object blocker) { + doParkNanos(blocker, 0L); + } + + public static void parkNanos(Object blocker, long nanos) { + if (nanos <= 0) { + return; + } + + doParkNanos(blocker, nanos); + } + + private static void doParkNanos(Object blocker, long nanos) { + Thread t = Thread.currentThread(); + setBlocker(t, blocker); + unsafe.park(false, nanos); + setBlocker(t, null); + } + + public static void parkUntil(Object blocker, long deadline) { + Thread t = Thread.currentThread(); + setBlocker(t, blocker); + unsafe.park(true, deadline); + setBlocker(t, null); + } + + public static Object getBlocker(Thread t) { + if (t == null) { + throw new NullPointerException(); + } + + return unsafe.getObjectVolatile(t, parkBlockerOffset); + } + + public static void park() { + unsafe.park(false, 0L); + } + + public static void parkNanos(long nanos) { + if (nanos > 0) { + unsafe.park(false, nanos); + } + } + + public static void parkUntil(long deadline) { + unsafe.park(true, deadline); + } +} diff --git a/classpath/java/util/concurrent/locks/ReadWriteLock.java b/classpath/java/util/concurrent/locks/ReadWriteLock.java new file mode 100644 index 0000000000..a4804e5fa4 --- /dev/null +++ b/classpath/java/util/concurrent/locks/ReadWriteLock.java @@ -0,0 +1,16 @@ +/* Copyright (c) 2008-2014, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.util.concurrent.locks; + +public interface ReadWriteLock { + public Lock readLock(); + public Lock writeLock(); +}