2011-10-04 21:17:01 +02:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-10-04 21:17:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.dispatch;
|
|
|
|
|
|
2012-04-26 02:12:59 +02:00
|
|
|
import akka.util.Unsafe;
|
2011-10-04 21:17:01 +02:00
|
|
|
|
|
|
|
|
abstract class AbstractPromise {
|
2012-04-26 10:55:51 +02:00
|
|
|
private volatile Object _ref = DefaultPromise.EmptyPending();
|
2012-04-26 02:12:59 +02:00
|
|
|
|
2012-04-26 10:55:51 +02:00
|
|
|
final static long _refOffset; // Memory offset to _ref field
|
2012-04-26 02:12:59 +02:00
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
try {
|
|
|
|
|
_refOffset = Unsafe.instance.objectFieldOffset(AbstractPromise.class.getDeclaredField("_ref"));
|
|
|
|
|
} catch(Throwable t){
|
|
|
|
|
throw new ExceptionInInitializerError(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected final boolean updateState(Object oldState, Object newState) {
|
|
|
|
|
return Unsafe.instance.compareAndSwapObject(this, _refOffset, oldState, newState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected final Object getState() {
|
2012-04-26 10:55:51 +02:00
|
|
|
return _ref;
|
2012-04-26 02:12:59 +02:00
|
|
|
}
|
2011-10-04 21:17:01 +02:00
|
|
|
}
|