Skip to content

Commit a567659

Browse files
committed
Made LockFreeLinkedList internal
1 parent c581454 commit a567659

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kotlinx.coroutines.experimental
22

3-
import kotlinx.coroutines.experimental.util.LockFreeLinkedListHead
4-
import kotlinx.coroutines.experimental.util.LockFreeLinkedListNode
3+
import kotlinx.coroutines.experimental.internal.LockFreeLinkedListHead
4+
import kotlinx.coroutines.experimental.internal.LockFreeLinkedListNode
55
import java.util.concurrent.CancellationException
66
import java.util.concurrent.Future
77
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
@@ -120,7 +120,7 @@ public open class JobSupport(
120120
) : AbstractCoroutineContextElement(Job), Job {
121121
// keeps a stack of cancel listeners or a special CANCELLED, other values denote completed scope
122122
@Volatile
123-
private var state: Any? = Active() // will drop the list on cancel
123+
private var state: Any? = ActiveList() // will drop the list on cancel
124124

125125
// directly pass HandlerNode to parent scope to optimize one closure object (see makeNode)
126126
private val registration: Job.Registration? = parent?.onCompletion(CancelOnCompletion(parent, this))
@@ -134,7 +134,7 @@ public open class JobSupport(
134134
protected fun getState(): Any? = state
135135

136136
protected fun updateState(expect: Any, update: Any?): Boolean {
137-
expect as Active // assert type
137+
expect as ActiveList // assert type
138138
require(update !is Active) // only active -> inactive transition is allowed
139139
if (!STATE.compareAndSet(this, expect, update)) return false
140140
// #1. Unregister from parent job
@@ -169,6 +169,7 @@ public open class JobSupport(
169169
return EmptyRegistration
170170
}
171171
val node = nodeCache ?: makeNode(handler).apply { nodeCache = this }
172+
state as ActiveList // assert type
172173
if (state.addLastIf(node) { this.state == state }) return node
173174
}
174175
}
@@ -188,7 +189,9 @@ public open class JobSupport(
188189
(handler as? JobNode)?.also { require(it.job === this) }
189190
?: InvokeOnCompletion(this, handler)
190191

191-
protected class Active : LockFreeLinkedListHead()
192+
protected interface Active
193+
194+
private class ActiveList : LockFreeLinkedListHead(), Active
192195

193196
protected abstract class CompletedExceptionally {
194197
abstract val cancelReason: Throwable?

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/util/LockFreeLinkedList.kt renamed to kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedList.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kotlinx.coroutines.experimental.util
1+
package kotlinx.coroutines.experimental.internal
22

33
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater
44
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
@@ -14,7 +14,7 @@ private typealias Node = LockFreeLinkedListNode
1414
* Sentinel node should be never removed.
1515
*/
1616
@Suppress("LeakingThis")
17-
public open class LockFreeLinkedListNode {
17+
internal open class LockFreeLinkedListNode {
1818
@Volatile
1919
private var _next: Any = this // DoubleLinkedNode | Removed | CondAdd
2020
@Volatile
@@ -241,7 +241,7 @@ public open class LockFreeLinkedListNode {
241241
}
242242
}
243243

244-
public open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
244+
internal open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
245245
/**
246246
* Iterates over all elements in this list of a specified type.
247247
*/
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
package kotlinx.coroutines.experimental.util
1+
package kotlinx.coroutines.experimental.internal
22

33
import org.junit.Test
44
import java.util.*
55
import java.util.concurrent.atomic.AtomicInteger
66
import kotlin.concurrent.thread
77

88
class LockFreeLinkedListStressTest {
9-
data class IntNode(val i: Int) : LockFreeLinkedListNode()
10-
11-
val list = LockFreeLinkedListHead()
9+
private data class IntNode(val i: Int) : LockFreeLinkedListNode()
10+
private val list = LockFreeLinkedListHead()
1211

1312
val threads = mutableListOf<Thread>()
1413
val nAdded = 10_000_000

kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/util/LockFreeLinkedListTest.kt renamed to kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedListTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kotlinx.coroutines.experimental.util
1+
package kotlinx.coroutines.experimental.internal
22

33
import org.junit.Assert.*
44
import org.junit.Test

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@
174174
</goals>
175175
</execution>
176176
</executions>
177+
<configuration>
178+
<args>-Xcoroutines=enable</args>
179+
</configuration>
177180
</plugin>
178181

179182
</plugins>

0 commit comments

Comments
 (0)