-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathConcurrent.common.kt
37 lines (30 loc) · 1.29 KB
/
Concurrent.common.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package kotlinx.coroutines.internal
internal expect class ReentrantLock()
internal expect inline fun <T> ReentrantLock.withLock(action: () -> T): T
internal expect fun <E> identitySet(expectedSize: Int): MutableSet<E>
/**
* 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<V>(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 <T> WorkaroundAtomicReference<T>.value: T
get() = this.get()
set(value) = this.set(value)
internal inline fun <T> WorkaroundAtomicReference<T>.loop(action: WorkaroundAtomicReference<T>.(value: T) -> Unit) {
while (true) {
action(value)
}
}