commonMain.internal.Concurrent.common.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-coroutines-core
Show all versions of kotlinx-coroutines-core
Coroutines support libraries for Kotlin
package kotlinx.coroutines.internal
internal expect class ReentrantLock() {
fun tryLock(): Boolean
fun unlock()
}
internal expect inline fun ReentrantLock.withLock(action: () -> T): T
internal expect fun identitySet(expectedSize: Int): MutableSet
/**
* Annotation indicating that the marked property is the subject of benign data race.
* LLVM does not support this notion, so on K/N platforms we alias it into `@Volatile` to prevent potential OoTA.
*
* The purpose of this annotation is not to save an extra-volatile on JVM platform, but rather to explicitly emphasize
* that data-race is benign.
*/
@OptionalExpectation
@Target(AnnotationTarget.FIELD)
internal expect annotation class BenignDataRace()
// Used **only** as a workaround for #3820 in StateFlow. Do not use anywhere else
internal expect class WorkaroundAtomicReference(value: V) {
public fun get(): V
public fun set(value: V)
public fun getAndSet(value: V): V
public fun compareAndSet(expected: V, value: V): Boolean
}
@Suppress("UNUSED_PARAMETER", "EXTENSION_SHADOWED_BY_MEMBER")
internal var WorkaroundAtomicReference.value: T
get() = this.get()
set(value) = this.set(value)
internal inline fun WorkaroundAtomicReference.loop(action: WorkaroundAtomicReference.(value: T) -> Unit) {
while (true) {
action(value)
}
}