src/share/classes/java/util/concurrent/atomic/AtomicLongArray.java
Print this page
*** 142,158 ****
* @param i the index
* @param newValue the new value
* @return the previous value
*/
public final long getAndSet(int i, long newValue) {
! long offset = checkedByteOffset(i);
! while (true) {
! long 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.
*
--- 142,153 ----
* @param i the index
* @param newValue the new value
* @return the previous value
*/
public final long getAndSet(int i, long newValue) {
! return unsafe.getAndSetLong(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.
*
*** 179,189 ****
* 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, long expect, long update) {
return compareAndSet(i, expect, update);
}
--- 174,184 ----
* 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, long expect, long update) {
return compareAndSet(i, expect, update);
}
*** 213,248 ****
* @param i the index
* @param delta the value to add
* @return the previous value
*/
public final long getAndAdd(int i, long delta) {
! long offset = checkedByteOffset(i);
! while (true) {
! long current = getRaw(offset);
! if (compareAndSetRaw(offset, current, current + delta))
! return current;
}
- }
/**
* Atomically increments by one the element at index {@code i}.
*
* @param i the index
* @return the updated value
*/
public final long incrementAndGet(int i) {
! return addAndGet(i, 1);
}
/**
* Atomically decrements by one the element at index {@code i}.
*
* @param i the index
* @return the updated value
*/
public final long decrementAndGet(int i) {
! return addAndGet(i, -1);
}
/**
* Atomically adds the given value to the element at index {@code i}.
*
--- 208,238 ----
* @param i the index
* @param delta the value to add
* @return the previous value
*/
public final long getAndAdd(int i, long delta) {
! return unsafe.getAndAddLong(array, checkedByteOffset(i), delta);
}
/**
* Atomically increments by one the element at index {@code i}.
*
* @param i the index
* @return the updated value
*/
public final long incrementAndGet(int i) {
! return getAndAdd(i, 1) + 1;
}
/**
* Atomically decrements by one the element at index {@code i}.
*
* @param i the index
* @return the updated value
*/
public final long decrementAndGet(int i) {
! return getAndAdd(i, -1) - 1;
}
/**
* Atomically adds the given value to the element at index {@code i}.
*
*** 249,266 ****
* @param i the index
* @param delta the value to add
* @return the updated value
*/
public long addAndGet(int i, long delta) {
! long offset = checkedByteOffset(i);
! while (true) {
! long current = getRaw(offset);
! long next = current + delta;
! if (compareAndSetRaw(offset, current, next))
! return next;
}
- }
/**
* Returns the String representation of the current values of array.
* @return the String representation of the current values of array
*/
--- 239,250 ----
* @param i the index
* @param delta the value to add
* @return the updated value
*/
public long addAndGet(int i, long delta) {
! return getAndAdd(i, delta) + delta;
}
/**
* Returns the String representation of the current values of array.
* @return the String representation of the current values of array
*/