src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java
Print this page
*** 157,174 ****
*
* @param i the index
* @param newValue the new value
* @return the previous value
*/
public final E getAndSet(int i, E newValue) {
! long offset = checkedByteOffset(i);
! while (true) {
! E current = getRaw(offset);
! if (compareAndSetRaw(offset, current, newValue))
! return current;
}
- }
/**
* Atomically sets the element at position {@code i} to the given
* updated value if the current value {@code ==} the expected value.
*
--- 157,170 ----
*
* @param i the index
* @param newValue the new value
* @return the previous value
*/
+ @SuppressWarnings("unchecked")
public final E getAndSet(int i, E newValue) {
! return (E)unsafe.getAndSetObject(array, checkedByteOffset(i), newValue);
}
/**
* Atomically sets the element at position {@code i} to the given
* updated value if the current value {@code ==} the expected value.
*
*** 195,205 ****
* appropriate alternative to {@code compareAndSet}.
*
* @param i the index
* @param expect the expected value
* @param update the new value
! * @return true if successful.
*/
public final boolean weakCompareAndSet(int i, E expect, E update) {
return compareAndSet(i, expect, update);
}
--- 191,201 ----
* appropriate alternative to {@code compareAndSet}.
*
* @param i the index
* @param expect the expected value
* @param update the new value
! * @return true if successful
*/
public final boolean weakCompareAndSet(int i, E expect, E update) {
return compareAndSet(i, expect, update);
}