Methods Summary |
---|
public final int | addAndGet(int i, int delta)Atomically adds the given value to the element at index {@code i}.
while (true) {
int current = get(i);
int next = current + delta;
if (compareAndSet(i, current, next))
return next;
}
|
public final boolean | compareAndSet(int i, int expect, int update)Atomically sets the element at position {@code i} to the given
updated value if the current value {@code ==} the expected value.
return unsafe.compareAndSwapInt(array, rawIndex(i),
expect, update);
|
public final int | decrementAndGet(int i)Atomically decrements by one the element at index {@code i}.
while (true) {
int current = get(i);
int next = current - 1;
if (compareAndSet(i, current, next))
return next;
}
|
public final int | get(int i)Gets the current value at position {@code i}.
return unsafe.getIntVolatile(array, rawIndex(i));
|
public final int | getAndAdd(int i, int delta)Atomically adds the given value to the element at index {@code i}.
while (true) {
int current = get(i);
int next = current + delta;
if (compareAndSet(i, current, next))
return current;
}
|
public final int | getAndDecrement(int i)Atomically decrements by one the element at index {@code i}.
while (true) {
int current = get(i);
int next = current - 1;
if (compareAndSet(i, current, next))
return current;
}
|
public final int | getAndIncrement(int i)Atomically increments by one the element at index {@code i}.
while (true) {
int current = get(i);
int next = current + 1;
if (compareAndSet(i, current, next))
return current;
}
|
public final int | getAndSet(int i, int newValue)Atomically sets the element at position {@code i} to the given
value and returns the old value.
while (true) {
int current = get(i);
if (compareAndSet(i, current, newValue))
return current;
}
|
public final int | incrementAndGet(int i)Atomically increments by one the element at index {@code i}.
while (true) {
int current = get(i);
int next = current + 1;
if (compareAndSet(i, current, next))
return next;
}
|
public final void | lazySet(int i, int newValue)Eventually sets the element at position {@code i} to the given value.
unsafe.putOrderedInt(array, rawIndex(i), newValue);
|
public final int | length()Returns the length of the array.
return array.length;
|
private long | rawIndex(int i)
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
return base + i * scale;
|
public final void | set(int i, int newValue)Sets the element at position {@code i} to the given value.
unsafe.putIntVolatile(array, rawIndex(i), newValue);
|
public java.lang.String | toString()Returns the String representation of the current values of array.
if (array.length > 0) // force volatile read
get(0);
return Arrays.toString(array);
|
public final boolean | weakCompareAndSet(int i, int expect, int update)Atomically sets the element at position {@code i} to the given
updated value if the current value {@code ==} the expected value.
May fail spuriously
and does not provide ordering guarantees, so is only rarely an
appropriate alternative to {@code compareAndSet}.
return compareAndSet(i, expect, update);
|