All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmAndroidMain.com.lehaine.littlekt.log.KtAtomicRef.kt Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package com.lehaine.littlekt.log

import java.util.concurrent.atomic.AtomicReference

/**
 * @author Colton Daily
 * @date 11/25/2021
 */
internal actual class KtAtomicRef actual constructor(initial: T) {
    private val ref = AtomicReference(initial)

    actual var value: T
        get() = ref.get()
        set(value) {
            ref.set(value)
        }

    actual inline fun update(block: (T) -> T) {
        do {
            val old = ref.get()
            val new = block(old)
        } while (!ref.compareAndSet(old, new))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy