1.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java Thu Oct 03 15:40:35 2013 +0200
1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java Fri Oct 04 10:52:01 2013 +0200
1.3 @@ -34,7 +34,6 @@
1.4 */
1.5
1.6 package java.util.concurrent.atomic;
1.7 -import sun.misc.Unsafe;
1.8
1.9 /**
1.10 * A {@code boolean} value that may be updated atomically. See the
1.11 @@ -49,16 +48,6 @@
1.12 */
1.13 public class AtomicBoolean implements java.io.Serializable {
1.14 private static final long serialVersionUID = 4654671469794556979L;
1.15 - // setup to use Unsafe.compareAndSwapInt for updates
1.16 - private static final Unsafe unsafe = Unsafe.getUnsafe();
1.17 - private static final long valueOffset;
1.18 -
1.19 - static {
1.20 - try {
1.21 - valueOffset = unsafe.objectFieldOffset
1.22 - (AtomicBoolean.class.getDeclaredField("value"));
1.23 - } catch (Exception ex) { throw new Error(ex); }
1.24 - }
1.25
1.26 private volatile int value;
1.27
1.28 @@ -98,7 +87,12 @@
1.29 public final boolean compareAndSet(boolean expect, boolean update) {
1.30 int e = expect ? 1 : 0;
1.31 int u = update ? 1 : 0;
1.32 - return unsafe.compareAndSwapInt(this, valueOffset, e, u);
1.33 + if (this.value == e) {
1.34 + this.value = u;
1.35 + return true;
1.36 + } else {
1.37 + return false;
1.38 + }
1.39 }
1.40
1.41 /**
1.42 @@ -114,9 +108,7 @@
1.43 * @return true if successful.
1.44 */
1.45 public boolean weakCompareAndSet(boolean expect, boolean update) {
1.46 - int e = expect ? 1 : 0;
1.47 - int u = update ? 1 : 0;
1.48 - return unsafe.compareAndSwapInt(this, valueOffset, e, u);
1.49 + return compareAndSet(expect, update);
1.50 }
1.51
1.52 /**
1.53 @@ -135,8 +127,7 @@
1.54 * @since 1.6
1.55 */
1.56 public final void lazySet(boolean newValue) {
1.57 - int v = newValue ? 1 : 0;
1.58 - unsafe.putOrderedInt(this, valueOffset, v);
1.59 + set(newValue);
1.60 }
1.61
1.62 /**