Methods Summary |
---|
public final boolean | compareAndSet(boolean expect, boolean update)Atomically sets the value to the given updated value
if the current value {@code ==} the expected value.
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
|
public final boolean | get()Returns the current value.
return value != 0;
|
public final boolean | getAndSet(boolean newValue)Atomically sets to the given value and returns the previous value.
for (;;) {
boolean current = get();
if (compareAndSet(current, newValue))
return current;
}
|
public final void | lazySet(boolean newValue)Eventually sets to the given value.
int v = newValue ? 1 : 0;
unsafe.putOrderedInt(this, valueOffset, v);
|
public final void | set(boolean newValue)Unconditionally sets to the given value.
value = newValue ? 1 : 0;
|
public java.lang.String | toString()Returns the String representation of the current value.
return Boolean.toString(get());
|
public boolean | weakCompareAndSet(boolean expect, boolean update)Atomically sets the value to the given updated value
if the current value {@code ==} the expected value.
May fail spuriously
and does not provide ordering guarantees, so is only rarely an
appropriate alternative to {@code compareAndSet}.
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
|