src/share/classes/java/util/concurrent/atomic/AtomicReference.java
Print this page
*** 122,132 ****
* 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 final boolean weakCompareAndSet(V expect, V update) {
return unsafe.compareAndSwapObject(this, valueOffset, expect, update);
}
--- 122,132 ----
* 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 final boolean weakCompareAndSet(V expect, V update) {
return unsafe.compareAndSwapObject(this, valueOffset, expect, update);
}
*** 134,154 ****
* Atomically sets to the given value and returns the old value.
*
* @param newValue the new value
* @return the previous value
*/
public final V getAndSet(V newValue) {
! while (true) {
! V x = get();
! if (compareAndSet(x, newValue))
! return x;
}
- }
/**
* Returns the String representation of the current value.
! * @return the String representation of the current value.
*/
public String toString() {
return String.valueOf(get());
}
--- 134,151 ----
* Atomically sets to the given value and returns the old value.
*
* @param newValue the new value
* @return the previous value
*/
+ @SuppressWarnings("unchecked")
public final V getAndSet(V newValue) {
! return (V)unsafe.getAndSetObject(this, valueOffset, newValue);
}
/**
* Returns the String representation of the current value.
! * @return the String representation of the current value
*/
public String toString() {
return String.valueOf(get());
}