File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
kotlinx-coroutines-core/jvm/src/scheduling Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -10,17 +10,22 @@ private val parallelismCompensationEnabled: Boolean =
10
10
* After the [body] completes, the effective parallelism may stay higher than the associated limit, but it is said
11
11
* that eventually it will adjust to meet it.
12
12
*/
13
- internal fun <T > withCompensatedParallelism (body : () -> T ): T {
13
+ @Suppress(" NOTHING_TO_INLINE" ) // better stacktrace
14
+ internal inline fun <T > withCompensatedParallelism (noinline body : () -> T ): T {
14
15
if (! parallelismCompensationEnabled) {
15
16
return body()
16
17
}
17
18
// CoroutineScheduler.Worker implements ParallelismCompensation
18
19
val worker = Thread .currentThread() as ? ParallelismCompensation
19
20
? : return body()
20
- worker.increaseParallelismAndLimit()
21
+ return worker.withCompensatedParallelism(body)
22
+ }
23
+
24
+ private fun <T > ParallelismCompensation.withCompensatedParallelism (body : () -> T ): T {
25
+ increaseParallelismAndLimit()
21
26
try {
22
27
return body()
23
28
} finally {
24
- worker. decreaseParallelismLimit()
29
+ decreaseParallelismLimit()
25
30
}
26
31
}
You can’t perform that action at this time.
0 commit comments