Methods Summary |
---|
public long | addAndGet(int i, long delta)Atomically adds the given value to the element at index {@code i}.
while (true) {
long current = get(i);
long next = current + delta;
if (compareAndSet(i, current, next))
return next;
}
|
public final boolean | compareAndSet(int i, long expect, long update)Atomically sets the value to the given updated value
if the current value {@code ==} the expected value.
return unsafe.compareAndSwapLong(array, rawIndex(i),
expect, update);
|
public final long | decrementAndGet(int i)Atomically decrements by one the element at index {@code i}.
while (true) {
long current = get(i);
long next = current - 1;
if (compareAndSet(i, current, next))
return next;
}
|
public final long | get(int i)Gets the current value at position {@code i}.
return unsafe.getLongVolatile(array, rawIndex(i));
|
public final long | getAndAdd(int i, long delta)Atomically adds the given value to the element at index {@code i}.
while (true) {
long current = get(i);
long next = current + delta;
if (compareAndSet(i, current, next))
return current;
}
|
public final long | getAndDecrement(int i)Atomically decrements by one the element at index {@code i}.
while (true) {
long current = get(i);
long next = current - 1;
if (compareAndSet(i, current, next))
return current;
}
|
public final long | getAndIncrement(int i)Atomically increments by one the element at index {@code i}.
while (true) {
long current = get(i);
long next = current + 1;
if (compareAndSet(i, current, next))
return current;
}
|
public final long | getAndSet(int i, long newValue)Atomically sets the element at position {@code i} to the given value
and returns the old value.
while (true) {
long current = get(i);
if (compareAndSet(i, current, newValue))
return current;
}
|
public final long | incrementAndGet(int i)Atomically increments by one the element at index {@code i}.
while (true) {
long current = get(i);
long next = current + 1;
if (compareAndSet(i, current, next))
return next;
}
|
public final void | lazySet(int i, long newValue)Eventually sets the element at position {@code i} to the given value.
unsafe.putOrderedLong(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, long newValue)Sets the element at position {@code i} to the given value.
unsafe.putLongVolatile(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, long expect, long update)Atomically sets the value 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);
|