/** * Atomically adds the given value to the current value. * * @param delta the value to add * @return the previous value */ public final long getAndAdd(long delta) { //$DELAY$ while (true) { //$DELAY$ long current = get(); long next = current + delta; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return current; } } }
/** * Atomically adds the given value to the current value. * * @param delta the value to add * @return the updated value */ public final long addAndGet(long delta) { //$DELAY$ for (;;) { //$DELAY$ long current = get(); long next = current + delta; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return next; } } }
/** * Atomically increments by one the current value. * * @return the updated value */ public final long incrementAndGet() { //$DELAY$ for (;;) { //$DELAY$ long current = get(); long next = current + 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return next; } } }
/** * Atomically sets to the given value and returns the old value. * * @param newValue the new value * @return the previous value */ public final long getAndSet(long newValue) { //$DELAY$ while (true) { //$DELAY$ long current = get(); //$DELAY$ if (compareAndSet(current, newValue)) { //$DELAY$ return current; } } }
/** * Atomically increments by one the current value. * * @return the previous value */ public final long getAndIncrement() { //$DELAY$ while (true) { //$DELAY$ long current = get(); long next = current + 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return current; } } }
/** * Atomically decrements by one the current value. * * @return the previous value */ public final long getAndDecrement() { //$DELAY$ while (true) { //$DELAY$ long current = get(); long next = current - 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return current; } } }
/** * Atomically decrements by one the current value. * * @return the updated value */ public final long decrementAndGet() { //$DELAY$ for (;;) { //$DELAY$ long current = get(); long next = current - 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return next; } } }
private void writeLatestUpdateTime( long updateTime ) { Atomic.Long atomicLong = db.getAtomicLong(LAST_SUCCESSFUL_UPDATE); long latestValue = atomicLong.get(); if (latestValue < updateTime) { atomicLong.compareAndSet(latestValue, updateTime); } } }
private void writeLatestUpdateTime( long updateTime ) { Atomic.Long atomicLong = db.getAtomicLong(LAST_SUCCESSFUL_UPDATE); long latestValue = atomicLong.get(); if (latestValue < updateTime) { atomicLong.compareAndSet(latestValue, updateTime); } } }