Search in sources :

Example 1 with AtomicLongFieldUpdater

use of java.util.concurrent.atomic.AtomicLongFieldUpdater in project j2objc by google.

the class Atomic8Test method testLongFieldUpdaterUpdateAndGet.

/**
 * AtomicLongFieldUpdater updateAndGet updates with supplied function and
 * returns result.
 */
public void testLongFieldUpdaterUpdateAndGet() {
    AtomicLongFieldUpdater a = aLongFieldUpdater();
    a.set(this, 1);
    assertEquals(18L, a.updateAndGet(this, Atomic8Test::addLong17));
    assertEquals(35L, a.updateAndGet(this, Atomic8Test::addLong17));
    assertEquals(35L, a.get(this));
    assertEquals(35L, aLongField);
}
Also used : AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater)

Example 2 with AtomicLongFieldUpdater

use of java.util.concurrent.atomic.AtomicLongFieldUpdater in project j2objc by google.

the class Atomic8Test method testLongFieldUpdaterGetAndAccumulate.

/**
 * AtomicLongFieldUpdater getAndAccumulate returns previous value
 * and updates with supplied function.
 */
public void testLongFieldUpdaterGetAndAccumulate() {
    AtomicLongFieldUpdater a = aLongFieldUpdater();
    a.set(this, 1);
    assertEquals(1L, a.getAndAccumulate(this, 2L, Long::sum));
    assertEquals(3L, a.getAndAccumulate(this, 3L, Long::sum));
    assertEquals(6L, a.get(this));
    assertEquals(6L, aLongField);
}
Also used : AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater)

Example 3 with AtomicLongFieldUpdater

use of java.util.concurrent.atomic.AtomicLongFieldUpdater in project j2objc by google.

the class Atomic8Test method testLongFieldUpdaterAccumulateAndGet.

/**
 * AtomicLongFieldUpdater accumulateAndGet updates with supplied
 * function and returns result.
 */
public void testLongFieldUpdaterAccumulateAndGet() {
    AtomicLongFieldUpdater a = aLongFieldUpdater();
    a.set(this, 1);
    assertEquals(7L, a.accumulateAndGet(this, 6L, Long::sum));
    assertEquals(10L, a.accumulateAndGet(this, 3L, Long::sum));
    assertEquals(10L, a.get(this));
    assertEquals(10L, aLongField);
}
Also used : AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater)

Example 4 with AtomicLongFieldUpdater

use of java.util.concurrent.atomic.AtomicLongFieldUpdater in project j2objc by google.

the class Atomic8Test method testLongFieldUpdaterGetAndUpdate.

/**
 * AtomicLongFieldUpdater getAndUpdate returns previous value and updates
 * result of supplied function
 */
public void testLongFieldUpdaterGetAndUpdate() {
    AtomicLongFieldUpdater a = aLongFieldUpdater();
    a.set(this, 1);
    assertEquals(1L, a.getAndUpdate(this, Atomic8Test::addLong17));
    assertEquals(18L, a.getAndUpdate(this, Atomic8Test::addLong17));
    assertEquals(35L, a.get(this));
    assertEquals(35L, aLongField);
}
Also used : AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater)

Aggregations

AtomicLongFieldUpdater (java.util.concurrent.atomic.AtomicLongFieldUpdater)4