You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/scheduling/CoroutineScheduler.kt
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -636,6 +636,8 @@ internal class CoroutineScheduler(
636
636
parkedWorkersStack.push(this)
637
637
}
638
638
639
+
if (!blockingQuiescence()) return
640
+
639
641
terminationState.value =ALLOWED
640
642
val time =System.nanoTime()
641
643
LockSupport.parkNanos(IDLE_WORKER_KEEP_ALIVE_NS)
@@ -649,14 +651,6 @@ internal class CoroutineScheduler(
649
651
* Stops execution of current thread and removes it from [createdWorkers]
650
652
*/
651
653
privatefunterminateWorker() {
652
-
// Last ditch polling: try to find blocking task before termination
653
-
val task = globalWorkQueue.pollBlockingMode()
654
-
if (task !=null) {
655
-
localQueue.add(task, globalWorkQueue)
656
-
return
657
-
}
658
-
659
-
660
654
synchronized(workers) {
661
655
// Someone else terminated, bail out
662
656
if (createdWorkers <= corePoolSize) {
@@ -671,6 +665,9 @@ internal class CoroutineScheduler(
671
665
return
672
666
}
673
667
668
+
// Last ditch polling: try to find blocking task before termination
669
+
if (!blockingQuiescence()) return
670
+
674
671
/*
675
672
* See tryUnpark for state reasoning.
676
673
* If this CAS fails, then we were successfully unparked by other worker and cannot terminate
@@ -690,6 +687,18 @@ internal class CoroutineScheduler(
690
687
state =WorkerState.FINISHED
691
688
}
692
689
690
+
/**
691
+
* Method checks whether new blocking tasks arrived to pool when worker decided
692
+
* it can go to deep park/termination and puts recently arrived task to its local queue
0 commit comments