File tree Expand file tree Collapse file tree 2 files changed +14
-21
lines changed
kotlinx-coroutines-core/jvm/src/scheduling
kotlinx-coroutines-debug/src/internal Expand file tree Collapse file tree 2 files changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -951,3 +951,12 @@ internal class CoroutineScheduler(
951
951
TERMINATED
952
952
}
953
953
}
954
+
955
+ @Suppress(" UNUSED" )
956
+ @JvmName(" isSchedulerWorker" )
957
+ internal fun isSchedulerWorker (thread : Thread ) = thread is CoroutineScheduler .Worker
958
+
959
+ @Suppress(" UNUSED" )
960
+ @JvmName(" mayNotBlock" )
961
+ internal fun mayNotBlock (thread : Thread ) = thread is CoroutineScheduler .Worker &&
962
+ thread.state == CoroutineScheduler .WorkerState .CPU_ACQUIRED
Original file line number Diff line number Diff line change
1
+ @file:Suppress(" INVISIBLE_REFERENCE" , " INVISIBLE_MEMBER" )
1
2
package kotlinx.coroutines.debug.internal
2
3
3
4
import reactor.blockhound.BlockHound
4
- import kotlin.reflect.KClass
5
- import kotlin.reflect.full.*
5
+ import kotlinx.coroutines.scheduling.*
6
6
7
7
internal object BlockHoundIntegration {
8
8
9
9
init {
10
- val cls = Class .forName(" kotlinx.coroutines.scheduling.CoroutineScheduler\$ Worker" ).kotlin
11
- initializerHelper(cls)
12
- }
13
-
14
- private fun <T : Any > initializerHelper (cls : KClass <T >) {
15
- val field = cls.declaredMemberProperties.find { it.name == " state" }!!
16
10
BlockHound .builder()
17
- .addDynamicThreadPredicate(cls::isInstance)
18
- .nonBlockingThreadPredicate { p ->
19
- p.or { thread ->
20
- val castThread = cls.safeCast(thread)
21
- if (! enabled || castThread == null ) {
22
- false
23
- } else {
24
- val state = field(castThread) as Enum <* >
25
- state.name == " CPU_ACQUIRED"
26
- }
27
- }
28
- }
29
- .install()
11
+ .addDynamicThreadPredicate { isSchedulerWorker(it) }
12
+ .nonBlockingThreadPredicate { p -> p.or { thread -> enabled && mayNotBlock(thread) } }
13
+ .install()
30
14
}
31
15
32
16
@Volatile
You can’t perform that action at this time.
0 commit comments