Added implementation and tests for FutureTask.

I also was missing the set operation for AtomicReference, and cleaned a couple things up from LockSupport.
This commit is contained in:
Mike Jensen
2014-03-10 10:53:49 -06:00
parent 492294bfe6
commit 83a31314e0
4 changed files with 250 additions and 9 deletions

View File

@ -23,16 +23,12 @@ public class LockSupport {
static {
unsafe = Unsafe.getUnsafe();
try {
parkBlockerOffset = unsafe.objectFieldOffset(java.lang.Thread.class.getDeclaredField("parkBlocker"));
parkBlockerOffset = unsafe.objectFieldOffset(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);
@ -53,16 +49,16 @@ public class LockSupport {
private static void doParkNanos(Object blocker, long nanos) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
unsafe.putObject(t, parkBlockerOffset, blocker);
unsafe.park(false, nanos);
setBlocker(t, null);
unsafe.putObject(t, parkBlockerOffset, null);
}
public static void parkUntil(Object blocker, long deadline) {
Thread t = Thread.currentThread();
setBlocker(t, blocker);
unsafe.putObject(t, parkBlockerOffset, blocker);
unsafe.park(true, deadline);
setBlocker(t, null);
unsafe.putObject(t, parkBlockerOffset, null);
}
public static Object getBlocker(Thread t) {