Skip to content

Commit 2006222

Browse files
committed
~properly short-circuit 0 blocking tasks
1 parent ffd9fd6 commit 2006222

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kotlinx-coroutines-core/jvm/src/scheduling/WorkQueue.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal class WorkQueue {
121121
var start = consumerIndex.value
122122
val end = producerIndex.value
123123

124-
while (start != end) {
124+
while (start != end && blockingTasksInBuffer.value > 0) {
125125
stolenTaskRef.element = tryExtractBlockingTask(start++) ?: continue
126126
return TASK_STOLEN
127127
}
@@ -141,7 +141,7 @@ internal class WorkQueue {
141141
val start = consumerIndex.value
142142
var end = producerIndex.value
143143

144-
while (start != end) {
144+
while (start != end && blockingTasksInBuffer.value > 0) {
145145
val task = tryExtractBlockingTask(--end)
146146
if (task != null) {
147147
return task
@@ -151,7 +151,6 @@ internal class WorkQueue {
151151
}
152152

153153
private fun tryExtractBlockingTask(index: Int): Task? {
154-
if (blockingTasksInBuffer.value == 0) return null
155154
val arrayIndex = index and MASK
156155
val value = buffer[arrayIndex]
157156
if (value != null && value.isBlocking && buffer.compareAndSet(arrayIndex, value, null)) {

0 commit comments

Comments
 (0)