mirror of
https://github.com/corda/corda.git
synced 2025-06-19 07:38:22 +00:00
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:
@ -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) {
|
||||
|
Reference in New Issue
Block a user