@@ -106,7 +106,7 @@ public actual open class LockFreeLinkedListNode {
106
106
// prev.next correction, which does not provide linearizable backwards iteration, but can be used to
107
107
// resume forward iteration when current node was removed.
108
108
public actual val prevNode: Node
109
- get() = correctPrev(null , true ) ? : findPrevNonRemoved(_prev .value)
109
+ get() = correctPrev(null ) ? : findPrevNonRemoved(_prev .value)
110
110
111
111
private tailrec fun findPrevNonRemoved (current : Node ): Node {
112
112
if (! current.isRemoved) return current
@@ -249,7 +249,7 @@ public actual open class LockFreeLinkedListNode {
249
249
val removed = (next as Node ).removed()
250
250
if (_next .compareAndSet(next, removed)) {
251
251
// was removed successfully (linearized remove) -- fixup the list
252
- next.correctPrev(null , false )
252
+ next.correctPrev(null )
253
253
return null
254
254
}
255
255
}
@@ -272,7 +272,7 @@ public actual open class LockFreeLinkedListNode {
272
272
node = next.ref
273
273
}
274
274
// Found a non-removed node
275
- node.correctPrev(null , false )
275
+ node.correctPrev(null )
276
276
}
277
277
278
278
public actual fun removeFirstOrNull (): Node ? {
@@ -332,7 +332,7 @@ public actual open class LockFreeLinkedListNode {
332
332
333
333
// Returns null when atomic op got into deadlock trying to help operation that started later (RETRY_ATOMIC)
334
334
final override fun takeAffectedNode (op : OpDescriptor ): Node ? =
335
- queue.correctPrev(op, true ) // queue head is never removed, so null result can only mean RETRY_ATOMIC
335
+ queue.correctPrev(op) // queue head is never removed, so null result can only mean RETRY_ATOMIC
336
336
337
337
private val _affectedNode = atomic<Node ?>(null )
338
338
final override val affectedNode: Node ? get() = _affectedNode .value
@@ -407,7 +407,7 @@ public actual open class LockFreeLinkedListNode {
407
407
final override fun finishOnSuccess (affected : Node , next : Node ) {
408
408
// Complete removal operation here. It bails out if next node is also removed and it becomes
409
409
// responsibility of the next's removes to call correctPrev which would help fix all the links.
410
- next.correctPrev(null , false )
410
+ next.correctPrev(null )
411
411
}
412
412
}
413
413
@@ -432,7 +432,7 @@ public actual open class LockFreeLinkedListNode {
432
432
if (affected._next .compareAndSet(this , removed)) {
433
433
// Complete removal operation here. It bails out if next node is also removed and it becomes
434
434
// responsibility of the next's removes to call correctPrev which would help fix all the links.
435
- next.correctPrev(null , false )
435
+ next.correctPrev(null )
436
436
}
437
437
return REMOVE_PREPARED
438
438
}
@@ -564,12 +564,8 @@ public actual open class LockFreeLinkedListNode {
564
564
* * When [op] descriptor is not `null` and and operation descriptor that is [OpDescriptor.isEarlierThan]
565
565
* that current [op] is found while traversing the list. This `null` result will be translated
566
566
* by callers to [RETRY_ATOMIC].
567
- *
568
- * @param [fixupPrev] when set to `true` this function ensure that `this.prev.next === this` after return from
569
- * this call. Otherwise, it will not retry on CAS failure. It is set to `true` when
570
- * looking for a previous node in [prevNode] in a linearizable way.
571
567
*/
572
- private tailrec fun correctPrev (op : OpDescriptor ? , fixupPrev : Boolean ): Node ? {
568
+ private tailrec fun correctPrev (op : OpDescriptor ? ): Node ? {
573
569
val oldPrev = _prev .value
574
570
var prev: Node = oldPrev
575
571
var last: Node ? = null // will be set so that last.next === prev
@@ -580,9 +576,9 @@ public actual open class LockFreeLinkedListNode {
580
576
prevNext == = this -> {
581
577
if (oldPrev == = prev) return prev // nothing to update -- all is fine, prev found
582
578
// otherwise need to update prev
583
- if (! this ._prev .compareAndSet(oldPrev, prev) && fixupPrev ) {
584
- // Note: retry from scratch on failure to update prev only when fixupPrev is true
585
- return correctPrev(op, true )
579
+ if (! this ._prev .compareAndSet(oldPrev, prev)) {
580
+ // Note: retry from scratch on failure to update prev
581
+ return correctPrev(op)
586
582
}
587
583
return prev // return a correct prev
588
584
}
@@ -593,13 +589,13 @@ public actual open class LockFreeLinkedListNode {
593
589
if (op != null && op.isEarlierThan(prevNext))
594
590
return null // RETRY_ATOMIC
595
591
prevNext.perform(prev)
596
- return correctPrev(op, fixupPrev ) // retry from scratch
592
+ return correctPrev(op) // retry from scratch
597
593
}
598
594
prevNext is Removed -> {
599
595
if (last != = null ) {
600
596
// newly added (prev) node is already removed, correct last.next around it
601
597
if (! last._next .compareAndSet(prev, prevNext.ref)) {
602
- return correctPrev(op, fixupPrev ) // retry from scratch on failure to update next
598
+ return correctPrev(op) // retry from scratch on failure to update next
603
599
}
604
600
prev = last
605
601
last = null
@@ -615,12 +611,8 @@ public actual open class LockFreeLinkedListNode {
615
611
}
616
612
}
617
613
618
- internal fun validateNode (prev : Node , next : Node , stress : Boolean ) {
619
- if (! stress) {
620
- // during stress test prev can be corrupted and it is Ok. It does not
621
- // have to absolutely correct as it is fixed on "as needed" basis
622
- assert { prev == = this ._prev .value }
623
- }
614
+ internal fun validateNode (prev : Node , next : Node ) {
615
+ assert { prev == = this ._prev .value }
624
616
assert { next == = this ._next .value }
625
617
}
626
618
@@ -660,15 +652,15 @@ public actual open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
660
652
override val isRemoved: Boolean get() = false
661
653
override fun nextIfRemoved (): Node ? = null
662
654
663
- internal fun validate (stress : Boolean = false ) {
655
+ internal fun validate () {
664
656
var prev: Node = this
665
657
var cur: Node = next as Node
666
658
while (cur != this ) {
667
659
val next = cur.nextNode
668
- cur.validateNode(prev, next, stress )
660
+ cur.validateNode(prev, next)
669
661
prev = cur
670
662
cur = next
671
663
}
672
- validateNode(prev, next as Node , stress )
664
+ validateNode(prev, next as Node )
673
665
}
674
666
}
0 commit comments