update

inline fun AtomicLong.update(block: (Long) -> Long): Long(source)
inline fun AtomicULong.update(block: (ULong) -> ULong): ULong(source)

Update value by AtomicLong.compareAndSet and then return the old value.

while (true) {
val current = value
if (compareAndSet(current, block(current))) {
return current
}
}

Return

The old value that been exchanged.


inline fun AtomicInt.update(block: (Int) -> Int): Int(source)
inline fun AtomicUInt.update(block: (UInt) -> UInt): UInt(source)

Update value by AtomicInt.compareAndSet and then return the old value.

while (true) {
val current = value
if (compareAndSet(current, block(current))) {
return current
}
}

Return

The old value that been exchanged.


inline fun <T> AtomicRef<T>.update(block: (T) -> T): T(source)

Update value by AtomicRef.compareAndSet and then return the old value.

while (true) {
val current = value
if (compareAndSet(current, block(current))) {
return current
}
}

Return

The old value that been exchanged.