use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class Atomic8Test method testIntArrayUpdateAndGet.
/**
* AtomicIntegerArray updateAndGet updates with supplied function and
* returns result.
*/
public void testIntArrayUpdateAndGet() {
AtomicIntegerArray a = new AtomicIntegerArray(1);
a.set(0, 1);
assertEquals(18, a.updateAndGet(0, Atomic8Test::addInt17));
assertEquals(35, a.updateAndGet(0, Atomic8Test::addInt17));
assertEquals(35, a.get(0));
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class Atomic8Test method testIntArrayGetAndUpdate.
/**
* AtomicIntegerArray getAndUpdate returns previous value and updates
* result of supplied function
*/
public void testIntArrayGetAndUpdate() {
AtomicIntegerArray a = new AtomicIntegerArray(1);
a.set(0, 1);
assertEquals(1, a.getAndUpdate(0, Atomic8Test::addInt17));
assertEquals(18, a.getAndUpdate(0, Atomic8Test::addInt17));
assertEquals(35, a.get(0));
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class Atomic8Test method testIntArrayGetAndAccumulate.
/**
* AtomicIntegerArray getAndAccumulate returns previous value and updates
* with supplied function.
*/
public void testIntArrayGetAndAccumulate() {
AtomicIntegerArray a = new AtomicIntegerArray(1);
a.set(0, 1);
assertEquals(1, a.getAndAccumulate(0, 2, Integer::sum));
assertEquals(3, a.getAndAccumulate(0, 3, Integer::sum));
assertEquals(6, a.get(0));
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class AtomicIntegerArrayTest method testGetLazySet.
/**
* get returns the last value lazySet at index by same thread
*/
public void testGetLazySet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.lazySet(i, 1);
assertEquals(1, aa.get(i));
aa.lazySet(i, 2);
assertEquals(2, aa.get(i));
aa.lazySet(i, -3);
assertEquals(-3, aa.get(i));
}
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class AtomicIntegerArrayTest method testWeakCompareAndSet.
/**
* repeated weakCompareAndSet succeeds in changing value when equal
* to expected
*/
public void testWeakCompareAndSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
do {
} while (!aa.weakCompareAndSet(i, 1, 2));
do {
} while (!aa.weakCompareAndSet(i, 2, -4));
assertEquals(-4, aa.get(i));
do {
} while (!aa.weakCompareAndSet(i, -4, 7));
assertEquals(7, aa.get(i));
}
}
Aggregations