* http://creativecommons.org/licenses/publicdomain
*/
-package java.util.concurrent.atomic;
-import sun.misc.Unsafe;
+//package java.util.concurrent.atomic;
+//import sun.misc.Unsafe;
/**
* A <tt>boolean</tt> value that may be updated atomically. See the
public class AtomicBoolean implements java.io.Serializable {
private static final long serialVersionUID = 4654671469794556979L;
// setup to use Unsafe.compareAndSwapInt for updates
- private static final Unsafe unsafe = Unsafe.getUnsafe();
+ /*private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final long valueOffset;
static {
valueOffset = unsafe.objectFieldOffset
(AtomicBoolean.class.getDeclaredField("value"));
} catch (Exception ex) { throw new Error(ex); }
- }
+ }*/
private volatile int value;
public final boolean compareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
- return unsafe.compareAndSwapInt(this, valueOffset, e, u);
+ synchronized (this) {
+ if(e == value) {
+ value = u;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ //return unsafe.compareAndSwapInt(this, valueOffset, e, u);
}
/**
public boolean weakCompareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
- return unsafe.compareAndSwapInt(this, valueOffset, e, u);
+ synchronized (this) {
+ if(e == value) {
+ value = u;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ //return unsafe.compareAndSwapInt(this, valueOffset, e, u);*/
}
/**
*/
public final void lazySet(boolean newValue) {
int v = newValue ? 1 : 0;
- unsafe.putOrderedInt(this, valueOffset, v);
+ synchronized (this) {
+ value = v;
+ }
+ //unsafe.putOrderedInt(this, valueOffset, v);
}
/**
* Returns the String representation of the current value.
* @return the String representation of the current value.
*/
- public String toString() {
+ /*public String toString() {
return Boolean.toString(get());
- }
+ }*/
}