Skip to content

Commit 5a6a7d9

Browse files
committed
~ Restore lock-freedom
1 parent 9c68b61 commit 5a6a7d9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,16 @@ public actual open class LockFreeLinkedListNode {
267267
// Helps with removal of nodes that are previous to this
268268
@PublishedApi
269269
internal fun helpRemovePrev() {
270-
correctPrev(null)
270+
// We need to call correctPrev on a non-removed node to ensure progress, since correctPrev bails out when
271+
// called on a removed node. There's always at least one non-removed node (list head).
272+
var node = this
273+
while (true) {
274+
val next = node.next
275+
if (next !is Removed) break
276+
node = next.ref
277+
}
278+
// Found a non-removed node
279+
node.correctPrev(null)
271280
}
272281

273282
public actual fun removeFirstOrNull(): Node? {

0 commit comments

Comments
 (0)