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: T) { public fun get(): T public fun set(value: T) public fun getAndSet(value: T): T public fun compareAndSet(expected: T, value: T): 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) } }