/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * value and returns the old value. * * @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. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return {@code true} if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * updated value if the current value {@code ==} the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { return compareAndSetRaw(checkedByteOffset(i), expect, update); }
/** * Atomically sets the element at position {@code i} to the given * value and returns the old value. * * @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 updates the element at index {@code i} with the results * of applying the given function, returning the previous value. The * function should be side-effect-free, since it may be re-applied * when attempted updates fail due to contention among threads. * * @param i the index * @param updateFunction a side-effect-free function * @return the previous value * @since 1.8 */ public final E getAndUpdate(int i, UnaryOperator<E> updateFunction) { long offset = checkedByteOffset(i); E prev, next; do { prev = getRaw(offset); next = updateFunction.apply(prev); } while (!compareAndSetRaw(offset, prev, next)); return prev; }
/** * Atomically sets the element at position {@code i} to the given * value and returns the old value. * * @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 * value and returns the old value. * * @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 updates the element at index {@code i} with the results * of applying the given function, returning the updated value. The * function should be side-effect-free, since it may be re-applied * when attempted updates fail due to contention among threads. * * @param i the index * @param updateFunction a side-effect-free function * @return the updated value * @since 1.8 */ public final E updateAndGet(int i, UnaryOperator<E> updateFunction) { long offset = checkedByteOffset(i); E prev, next; do { prev = getRaw(offset); next = updateFunction.apply(prev); } while (!compareAndSetRaw(offset, prev, next)); return next; }
/** * Atomically sets the element at position {@code i} to the given * value and returns the old value. * * @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 * value and returns the old value. * * @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 = (E) getRaw(offset); if (compareAndSetRaw(offset, current, newValue)) return current; } }
/** * Atomically sets the element at position {@code i} to the given * value and returns the old value. * * @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 * value and returns the old value. * * @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 updates the element at index {@code i} with the * results of applying the given function to the current and * given values, returning the updated value. The function should * be side-effect-free, since it may be re-applied when attempted * updates fail due to contention among threads. The function is * applied with the current value at index {@code i} as its first * argument, and the given update as the second argument. * * @param i the index * @param x the update value * @param accumulatorFunction a side-effect-free function of two arguments * @return the updated value * @since 1.8 */ public final E accumulateAndGet(int i, E x, BinaryOperator<E> accumulatorFunction) { long offset = checkedByteOffset(i); E prev, next; do { prev = getRaw(offset); next = accumulatorFunction.apply(prev, x); } while (!compareAndSetRaw(offset, prev, next)); return next; }