getAndUpdate

inline fun <V> AtomicRef<V>.getAndUpdate(function: (V) -> V): V

Updates variable atomically using the specified function of its value and returns its old value.