@@ -46,20 +46,18 @@ internal open class LockFreeLinkedListNode {
46
46
}
47
47
48
48
/* * @suppress **This is unstable API and it is subject to change.** */
49
- internal open class LockFreeLinkedListHead {
50
- private val head = LockFreeLinkedListSegment (
51
- id = 0 ,
52
- prev = null ,
53
- pointers = 2 ,
54
- head = this ,
55
- )
56
- private val tail = atomic(head)
49
+ internal open class LockFreeLinkedListHead : LockFreeLinkedListSegment (
50
+ id = 0 ,
51
+ prev = null ,
52
+ pointers = 2 ,
53
+ ) {
54
+ private val tail = atomic<LockFreeLinkedListSegment >(this )
57
55
private val nextElement = atomic(0L )
58
56
59
57
/* *
60
58
* The list of bits that are forbidden from entering the list.
61
59
*
62
- * TODO: we can store this in the extra bits in [head] , there's enough space for that there, and it's never removed .
60
+ * TODO: we can store this in `cleanedAndPointers` , there's enough space for that there.
63
61
*/
64
62
private val forbiddenBits: AtomicInt = atomic(0 )
65
63
@@ -122,17 +120,14 @@ internal open class LockFreeLinkedListHead {
122
120
null
123
121
}
124
122
}
123
+
124
+ override val head: LockFreeLinkedListHead get() = this
125
125
}
126
126
127
127
internal open class LockFreeLinkedListSegment (
128
128
id : Long ,
129
129
prev : LockFreeLinkedListSegment ? ,
130
130
pointers : Int ,
131
- /* * Used only during promoting of a single node to a list to ensure wait-freedom of the promotion operation.
132
- * Without this, promotion can't be implemented without a (possibly bounded) spin loop: once the node is committed
133
- * to be part of some list, the other threads can't do anything until that one thread sets the state to be the
134
- * head of the list. */
135
- @JvmField val head : LockFreeLinkedListHead ,
136
131
) : Segment<LockFreeLinkedListSegment>(id = id, prev = prev, pointers = pointers)
137
132
{
138
133
/* * Each cell is a [LockFreeLinkedListNode], a [BrokenForSomeElements], or `null`. */
@@ -188,6 +183,8 @@ internal open class LockFreeLinkedListSegment(
188
183
override fun onCancellation (index : Int , cause : Throwable ? , context : CoroutineContext ) {
189
184
throw UnsupportedOperationException (" Cancellation is not supported on LockFreeLinkedList" )
190
185
}
186
+
187
+ open val head: LockFreeLinkedListHead get() = prev!! .head
191
188
}
192
189
193
190
internal class Address (@JvmField val segment : LockFreeLinkedListSegment , @JvmField val index : Int )
@@ -197,7 +194,6 @@ private fun createSegment(id: Long, prev: LockFreeLinkedListSegment): LockFreeLi
197
194
id = id,
198
195
prev = prev,
199
196
pointers = 0 ,
200
- head = prev.head
201
197
)
202
198
203
199
private const val SEGMENT_SIZE = 8
0 commit comments