src/share/classes/java/util/concurrent/atomic/AtomicBoolean.java
Print this page
*** 109,119 ****
* and does not provide ordering guarantees, so is only rarely an
* appropriate alternative to {@code compareAndSet}.
*
* @param expect the expected value
* @param update the new value
! * @return true if successful.
*/
public boolean weakCompareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
--- 109,119 ----
* and does not provide ordering guarantees, so is only rarely an
* appropriate alternative to {@code compareAndSet}.
*
* @param expect the expected value
* @param update the new value
! * @return true if successful
*/
public boolean weakCompareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
*** 144,163 ****
*
* @param newValue the new value
* @return the previous value
*/
public final boolean getAndSet(boolean newValue) {
! for (;;) {
! boolean current = get();
! if (compareAndSet(current, newValue))
! return current;
}
- }
/**
* Returns the String representation of the current value.
! * @return the String representation of the current value.
*/
public String toString() {
return Boolean.toString(get());
}
--- 144,163 ----
*
* @param newValue the new value
* @return the previous value
*/
public final boolean getAndSet(boolean newValue) {
! boolean prev;
! do {
! prev = get();
! } while (!compareAndSet(prev, newValue));
! return prev;
}
/**
* Returns the String representation of the current value.
! * @return the String representation of the current value
*/
public String toString() {
return Boolean.toString(get());
}