File tree 1 file changed +14
-7
lines changed
kotlinx-coroutines-core/jvm/src/scheduling
1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -150,18 +150,25 @@ internal class WorkQueue {
150
150
var end = producerIndex.value
151
151
152
152
while (start != end) {
153
- -- end
154
- val index = end and MASK
155
- if (blockingTasksInBuffer.value == 0 ) break
156
- val value = buffer[index]
157
- if (value != null && value.isBlocking && buffer.compareAndSet(index, value, null )) {
158
- blockingTasksInBuffer.decrementAndGet()
159
- return value
153
+ val task = tryExtractBlockingTask(-- end)
154
+ if (task != null ) {
155
+ return task
160
156
}
161
157
}
162
158
return null
163
159
}
164
160
161
+ private fun tryExtractBlockingTask (index : Int ): Task ? {
162
+ if (blockingTasksInBuffer.value == 0 ) return null
163
+ val arrayIndex = index and MASK
164
+ val value = buffer[arrayIndex]
165
+ if (value != null && value.isBlocking && buffer.compareAndSet(arrayIndex, value, null )) {
166
+ blockingTasksInBuffer.decrementAndGet()
167
+ return value
168
+ }
169
+ return null
170
+ }
171
+
165
172
fun offloadAllWorkTo (globalQueue : GlobalQueue ) {
166
173
lastScheduledTask.getAndSet(null )?.let { globalQueue.addLast(it) }
167
174
while (pollTo(globalQueue)) {
You can’t perform that action at this time.
0 commit comments