Skip to content

Commit 6fa8981

Browse files
committed
Explicitly remember the boxed version
1 parent f6a517b commit 6fa8981

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ internal open class LockFreeLinkedListSegment(
145145
fun tryAdd(node: LockFreeLinkedListNode, permissionsBitmask: Byte, indexInSegment: Int): Boolean {
146146
if (cells[indexInSegment].compareAndSet(null, node)) return true
147147
cells[indexInSegment].loop { value ->
148+
val valueAsAny: Any? = value // explicitly remember the boxed value; the type must be explicitly written
148149
// This means that some elements are forbidden from entering the list.
149150
value as BrokenForSomeElements
150151
// Are *we* forbidden from entering the list?
@@ -154,7 +155,7 @@ internal open class LockFreeLinkedListSegment(
154155
return false
155156
}
156157
// We aren't forbidden. Let's try entering it.
157-
if (cells[indexInSegment].compareAndSet(value, node)) return true
158+
if (cells[indexInSegment].compareAndSet(valueAsAny, node)) return true
158159
}
159160
}
160161

0 commit comments

Comments
 (0)