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

nativeMain.internal.Concurrent.kt Maven / Gradle / Ivy

package kotlinx.coroutines.internal

import kotlinx.atomicfu.*
import kotlinx.cinterop.*
import kotlinx.atomicfu.locks.withLock as withLock2

@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias ReentrantLock = kotlinx.atomicfu.locks.SynchronizedObject

internal actual inline fun  ReentrantLock.withLock(action: () -> T): T = this.withLock2(action)

internal actual fun  identitySet(expectedSize: Int): MutableSet = HashSet()

@Suppress("ACTUAL_WITHOUT_EXPECT") // This suppress can be removed in 2.0: KT-59355
internal actual typealias BenignDataRace = kotlin.concurrent.Volatile

internal actual class WorkaroundAtomicReference actual constructor(value: V) {

    private val nativeAtomic = kotlin.concurrent.AtomicReference(value)

    public actual fun get(): V= nativeAtomic.value

    public actual fun set(value: V) {
        nativeAtomic.value = value
    }

    public actual fun getAndSet(value: V): V = nativeAtomic.getAndSet(value)

    public actual fun compareAndSet(expected: V, value: V): Boolean = nativeAtomic.compareAndSet(expected, value)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy