AtomicRef

expect class AtomicRef<V>(initialValue: V)(source)
actual class AtomicRef<V>(initialValue: V)(source)
actual typealias AtomicRef = AtomicReference<V>
actual class AtomicRef<V>(initialValue: V)(source)

Constructors

Link copied to clipboard
expect fun <V> AtomicRef(initialValue: V)
actual fun <V> AtomicRef(initialValue: V)
actual fun <V> AtomicRef(initialValue: V)

Functions

Link copied to clipboard
expect fun compareAndSet(expected: V, new: V): Boolean

Compare current value with expected and set to new if they're the same. Note, 'compare' is checking the actual object id, not 'equals'.

actual fun compareAndSet(expected: V, new: V): Boolean

Compare current value with expected and set to new if they're the same. Note, 'compare' is checking the actual object id, not 'equals'.

actual fun compareAndSet(expected: V, new: V): Boolean

Compare current value with expected and set to new if they're the same. Note, 'compare' is checking the actual object id, not 'equals'.

Link copied to clipboard
expect fun get(): V
actual fun get(): V
actual fun get(): V
Link copied to clipboard
expect fun getAndSet(value: V): V
actual fun getAndSet(value: V): V
actual fun getAndSet(value: V): V
Link copied to clipboard
expect fun set(value: V)
actual fun set(value: V)
actual fun set(value: V)

Extensions

Link copied to clipboard
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.

Link copied to clipboard
inline fun <V> AtomicRef<V>.loop(action: (V) -> Unit): Nothing

Infinite loop that reads this atomic variable and performs the specified action on its value.

Link copied to clipboard
inline fun <V> AtomicRef<V>.update(function: (V) -> V)
Link copied to clipboard
inline fun <V> AtomicRef<V>.updateAndGet(function: (V) -> V): V

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