File tree 1 file changed +8
-3
lines changed
kotlinx-coroutines-core/jvm/src/scheduling
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -713,7 +713,8 @@ internal class CoroutineScheduler(
713
713
// this code runs in a different worker thread that holds a CPU token
714
714
val cpuHolder = currentThread() as Worker
715
715
assert { cpuHolder.state == WorkerState .CPU_ACQUIRED }
716
- cpuHolder.giveAwayLocalTasks() // TODO probably we can move CPU tasks straight into acquiring worker's local queue
716
+ val releasedTasks = cpuHolder.giveAwayLocalTasks()
717
+ if (releasedTasks) signalCpuWork()
717
718
cpuHolder.state = WorkerState .BLOCKING
718
719
}, taskContext = NonBlockingContext )
719
720
permitTransfer.acquire(
@@ -724,14 +725,18 @@ internal class CoroutineScheduler(
724
725
decrementBlockingTasks()
725
726
}
726
727
727
- fun giveAwayLocalTasks () {
728
+ fun giveAwayLocalTasks (): Boolean {
729
+ // probably the right way would be to signalCpuWork() on each task, but it should be fine without it
730
+ var givenAwayAny: Boolean = false
728
731
stolenTask.element?.let { task ->
729
732
addToGlobalQueue(task)
730
733
stolenTask.element = null
734
+ givenAwayAny = true
731
735
}
732
736
while (true ) {
733
- val task = localQueue.poll() ? : return
737
+ val task = localQueue.poll() ? : return givenAwayAny
734
738
addToGlobalQueue(task)
739
+ givenAwayAny = true
735
740
}
736
741
}
737
742
You can’t perform that action at this time.
0 commit comments