@@ -91,7 +91,7 @@ public actual open class LockFreeLinkedListNode {
91
91
// prev.next correction, which does not provide linearizable backwards iteration, but can be used to
92
92
// resume forward iteration when current node was removed.
93
93
public actual val prevNode: Node
94
- get() = correctPrev(null ) ? : findPrevNonRemoved(_prev .value)
94
+ get() = correctPrev() ? : findPrevNonRemoved(_prev .value)
95
95
96
96
private tailrec fun findPrevNonRemoved (current : Node ): Node {
97
97
if (! current.isRemoved) return current
@@ -207,7 +207,7 @@ public actual open class LockFreeLinkedListNode {
207
207
val removed = (next as Node ).removed()
208
208
if (_next .compareAndSet(next, removed)) {
209
209
// was removed successfully (linearized remove) -- fixup the list
210
- next.correctPrev(null )
210
+ next.correctPrev()
211
211
return null
212
212
}
213
213
}
@@ -247,14 +247,12 @@ public actual open class LockFreeLinkedListNode {
247
247
if (next._prev .compareAndSet(nextPrev, this )) {
248
248
// This newly added node could have been removed, and the above CAS would have added it physically again.
249
249
// Let us double-check for this situation and correct if needed
250
- if (isRemoved) next.correctPrev(null )
250
+ if (isRemoved) next.correctPrev()
251
251
return
252
252
}
253
253
}
254
254
}
255
255
256
- protected open fun nextIfRemoved (): Node ? = (next as ? Removed )?.ref
257
-
258
256
/* *
259
257
* Returns the corrected value of the previous node while also correcting the `prev` pointer
260
258
* (so that `this.prev.next === this`) and helps complete node removals to the left ot this node.
@@ -265,7 +263,7 @@ public actual open class LockFreeLinkedListNode {
265
263
* remover of this node will ultimately call [correctPrev] on the next node and that will fix all
266
264
* the links from this node, too.
267
265
*/
268
- private tailrec fun correctPrev (op : OpDescriptor ? ): Node ? {
266
+ private tailrec fun correctPrev (): Node ? {
269
267
val oldPrev = _prev .value
270
268
var prev: Node = oldPrev
271
269
var last: Node ? = null // will be set so that last.next === prev
@@ -278,22 +276,21 @@ public actual open class LockFreeLinkedListNode {
278
276
// otherwise need to update prev
279
277
if (! this ._prev .compareAndSet(oldPrev, prev)) {
280
278
// Note: retry from scratch on failure to update prev
281
- return correctPrev(op )
279
+ return correctPrev()
282
280
}
283
281
return prev // return the correct prev
284
282
}
285
283
// slow path when we need to help remove operations
286
284
this .isRemoved -> return null // nothing to do, this node was removed, bail out asap to save time
287
- prevNext == = op -> return prev // part of the same op -- don't recurse, didn't correct prev
288
285
prevNext is OpDescriptor -> { // help & retry
289
286
prevNext.perform(prev)
290
- return correctPrev(op ) // retry from scratch
287
+ return correctPrev() // retry from scratch
291
288
}
292
289
prevNext is Removed -> {
293
290
if (last != = null ) {
294
291
// newly added (prev) node is already removed, correct last.next around it
295
292
if (! last._next .compareAndSet(prev, prevNext.ref)) {
296
- return correctPrev(op ) // retry from scratch on failure to update next
293
+ return correctPrev() // retry from scratch on failure to update next
297
294
}
298
295
prev = last
299
296
last = null
@@ -345,6 +342,4 @@ public actual open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
345
342
346
343
// optimization: because head is never removed, we don't have to read _next.value to check these:
347
344
override val isRemoved: Boolean get() = false
348
-
349
- override fun nextIfRemoved (): Node ? = null
350
345
}
0 commit comments