src/share/classes/java/util/concurrent/atomic/AtomicIntegerArray.java
Print this page
*** 143,159 ****
* @param i the index
* @param newValue the new value
* @return the previous value
*/
public final int getAndSet(int i, int newValue) {
! long offset = checkedByteOffset(i);
! while (true) {
! int 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.
*
--- 143,154 ----
* @param i the index
* @param newValue the new value
* @return the previous value
*/
public final int getAndSet(int i, int newValue) {
! return unsafe.getAndSetInt(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.
*
*** 180,190 ****
* 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, int expect, int update) {
return compareAndSet(i, expect, update);
}
--- 175,185 ----
* 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, int expect, int update) {
return compareAndSet(i, expect, update);
}
*** 214,249 ****
* @param i the index
* @param delta the value to add
* @return the previous value
*/
public final int getAndAdd(int i, int delta) {
! long offset = checkedByteOffset(i);
! while (true) {
! int 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 int 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 int decrementAndGet(int i) {
! return addAndGet(i, -1);
}
/**
* Atomically adds the given value to the element at index {@code i}.
*
--- 209,239 ----
* @param i the index
* @param delta the value to add
* @return the previous value
*/
public final int getAndAdd(int i, int delta) {
! return unsafe.getAndAddInt(array, checkedByteOffset(i), delta);
}
/**
* Atomically increments by one the element at index {@code i}.
*
* @param i the index
* @return the updated value
*/
public final int 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 int decrementAndGet(int i) {
! return getAndAdd(i, -1) - 1;
}
/**
* Atomically adds the given value to the element at index {@code i}.
*
*** 250,267 ****
* @param i the index
* @param delta the value to add
* @return the updated value
*/
public final int addAndGet(int i, int delta) {
! long offset = checkedByteOffset(i);
! while (true) {
! int current = getRaw(offset);
! int 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
*/
--- 240,251 ----
* @param i the index
* @param delta the value to add
* @return the updated value
*/
public final int addAndGet(int i, int 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
*/