• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.coroutines.internal.*
8 import platform.posix.*
9 import kotlin.native.concurrent.*
10 import kotlin.random.*
11 
randomWaitnull12 actual fun randomWait() {
13     val n = Random.nextInt(1000)
14     if (n < 500) return // no wait 50% of time
15     repeat(n) {
16         BlackHole.sink *= 3
17     }
18     // use the BlackHole value somehow, so even if the compiler gets smarter, it won't remove the object
19     val sinkValue = if (BlackHole.sink > 16) 1 else 0
20     if (n + sinkValue > 900) sched_yield()
21 }
22 
23 @ThreadLocal
24 private object BlackHole {
25     var sink = 1
26 }
27 
28 internal actual typealias SuppressSupportingThrowable = SuppressSupportingThrowableImpl
29 
30 actual val Throwable.suppressed: Array<Throwable>
31     get() = (this as? SuppressSupportingThrowableImpl)?.suppressed ?: emptyArray()
32 
33 @Suppress("EXTENSION_SHADOWED_BY_MEMBER", "unused")
printStackTracenull34 actual fun Throwable.printStackTrace() = printStackTrace()
35 
36 actual fun currentThreadName(): String = Worker.current.name
37