1 /* 2 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.exceptions 6 7 import kotlinx.atomicfu.* 8 import kotlinx.coroutines.internal.* 9 import platform.posix.* 10 import kotlin.native.concurrent.* 11 import kotlin.random.* 12 randomWaitnull13actual fun randomWait() { 14 val n = Random.nextInt(1000) 15 if (n < 500) return // no wait 50% of time 16 repeat(n) { 17 BlackHole.sink *= 3 18 } 19 // use the BlackHole value somehow, so even if the compiler gets smarter, it won't remove the object 20 val sinkValue = if (BlackHole.sink > 16) 1 else 0 21 if (n + sinkValue > 900) sched_yield() 22 } 23 24 @ThreadLocal 25 private object BlackHole { 26 var sink = 1 27 } 28 29 internal actual typealias SuppressSupportingThrowable = SuppressSupportingThrowableImpl 30 31 actual val Throwable.suppressed: Array<Throwable> 32 get() = (this as? SuppressSupportingThrowableImpl)?.suppressed ?: emptyArray() 33 34 @Suppress("EXTENSION_SHADOWED_BY_MEMBER") printStackTracenull35actual fun Throwable.printStackTrace() = printStackTrace() 36 37 actual fun currentThreadName(): String = Worker.current.name 38