-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathConcurrent.kt
37 lines (26 loc) · 1.15 KB
/
Concurrent.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
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.internal
import kotlinx.atomicfu.*
import kotlin.native.concurrent.*
import kotlinx.atomicfu.locks.withLock as withLock2
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias ReentrantLock = kotlinx.atomicfu.locks.SynchronizedObject
internal actual inline fun <T> ReentrantLock.withLock(action: () -> T): T = this.withLock2(action)
internal actual fun <E> subscriberList(): MutableList<E> = CopyOnWriteList<E>()
internal actual fun <E> identitySet(expectedSize: Int): MutableSet<E> = HashSet()
// "Suppress-supporting throwable" is currently used for tests only
internal open class SuppressSupportingThrowableImpl : Throwable() {
private val _suppressed = atomic<Array<Throwable>>(emptyArray())
val suppressed: Array<Throwable>
get() = _suppressed.value
fun addSuppressed(other: Throwable) {
_suppressed.update { current ->
current + other
}
}
}
@OptIn(ExperimentalStdlibApi::class)
internal val multithreadingSupported: Boolean
get() = kotlin.native.isExperimentalMM()