JobSupport is an internal class (its contracts are quite complex for public use)
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Builders.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Builders.kt
index efd1651..743d7d5 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Builders.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Builders.kt
@@ -77,7 +77,7 @@
}
}
-private class InnerCoroutine<T>(
+private class InnerCoroutine<in T>(
override val context: CoroutineContext,
continuation: Continuation<T>
) : Continuation<T> by continuation, CoroutineScope {
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineScope.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineScope.kt
index 3fc38c0..0b3c5ba 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineScope.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CoroutineScope.kt
@@ -25,7 +25,7 @@
* It stores the result of continuation in the state of the job.
*/
@Suppress("LeakingThis")
-public abstract class AbstractCoroutine<in T>(context: CoroutineContext) : JobSupport(), Continuation<T>, CoroutineScope {
+internal abstract class AbstractCoroutine<in T>(context: CoroutineContext) : JobSupport(), Continuation<T>, CoroutineScope {
override val context: CoroutineContext = context + this // merges this job into this context
final override fun resume(value: T) {
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt
index 8c3fa40..b284a18 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt
@@ -123,8 +123,7 @@
* This is an open class designed for extension by more specific classes that might augment the
* state and mare store addition state information for completed jobs, like their result values.
*/
-@Suppress("LeakingThis")
-public open class JobSupport : AbstractCoroutineContextElement(Job), Job {
+internal open class JobSupport : AbstractCoroutineContextElement(Job), Job {
/*
=== States ===
name state class is Active?
@@ -176,7 +175,7 @@
* Initializes parent job.
* It shall be invoked at most once after construction after all other initialization.
*/
- public fun initParentJob(parent: Job?) {
+ fun initParentJob(parent: Job?) {
if (parent == null) return
check(registration == null)
// directly pass HandlerNode to parent scope to optimize one closure object (see makeNode)
@@ -189,12 +188,12 @@
/**
* Returns current state of this job.
*/
- internal fun getState(): Any? = state
+ fun getState(): Any? = state
/**
* Tries to update current [state][getState] of this job.
*/
- protected fun updateState(expect: Any, update: Any?): Boolean {
+ fun updateState(expect: Any, update: Any?): Boolean {
require(expect is Active && update !is Active) // only active -> inactive transition is allowed
if (!STATE.compareAndSet(this, expect, update)) return false
// #1. Update linked state before invoking completion handlers
@@ -229,9 +228,9 @@
return true
}
- public final override val isActive: Boolean get() = state is Active
+ final override val isActive: Boolean get() = state is Active
- public final override fun onCompletion(handler: CompletionHandler): Job.Registration {
+ final override fun onCompletion(handler: CompletionHandler): Job.Registration {
var nodeCache: JobNode? = null
while (true) { // lock-free loop on state
val state = this.state
@@ -265,7 +264,7 @@
}
}
- internal fun removeNode(node: JobNode) {
+ fun removeNode(node: JobNode) {
// remove logic depends on the state of the job
while (true) { // lock-free loop on job state
val state = this.state
@@ -290,7 +289,7 @@
}
}
- public final override fun cancel(reason: Throwable?): Boolean {
+ final override fun cancel(reason: Throwable?): Boolean {
while (true) { // lock-free loop on state
val state = this.state as? Active ?: return false // quit if not active anymore
if (updateState(state, Cancelled(reason))) return true
@@ -300,19 +299,19 @@
/**
* Override to make linked state changes before completion handlers are invoked.
*/
- protected open fun onStateUpdate(update: Any?) {}
+ open fun onStateUpdate(update: Any?) {}
/**
* Override to process any exceptions that were encountered while invoking [onCompletion] handlers.
*/
- protected open fun handleCompletionException(closeException: Throwable) {
+ open fun handleCompletionException(closeException: Throwable) {
throw closeException
}
/**
* Override for post-completion actions that need to do something with the state.
*/
- protected open fun afterCompletion(state: Any?) {}
+ open fun afterCompletion(state: Any?) {}
private fun makeNode(handler: CompletionHandler): JobNode =
(handler as? JobNode)?.also { require(it.job === this) }
@@ -321,7 +320,7 @@
/**
* Marker interface for active [state][getState] of a job.
*/
- public interface Active
+ internal interface Active
private object Empty : Active
@@ -330,7 +329,7 @@
/**
* Abstract class for a [state][getState] of a job that had completed exceptionally, including cancellation.
*/
- public abstract class CompletedExceptionally {
+ internal abstract class CompletedExceptionally {
abstract val cancelReason: Throwable // original reason or fresh CancellationException
abstract val exception: Throwable // the exception to be thrown in continuation
}
@@ -338,7 +337,7 @@
/**
* Represents a [state][getState] of a cancelled job.
*/
- public class Cancelled(specifiedReason: Throwable?) : CompletedExceptionally() {
+ internal class Cancelled(specifiedReason: Throwable?) : CompletedExceptionally() {
@Volatile
private var _cancelReason = specifiedReason // materialize CancellationException on first need
@@ -359,7 +358,7 @@
/**
* Represents a [state][getState] of a failed job.
*/
- public class Failed(override val exception: Throwable) : CompletedExceptionally() {
+ internal class Failed(override val exception: Throwable) : CompletedExceptionally() {
override val cancelReason: Throwable
get() = exception
}
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/LazyDeferred.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/LazyDeferred.kt
index 3121d4a..5b2f3db 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/LazyDeferred.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/LazyDeferred.kt
@@ -17,7 +17,7 @@
* If this lazy deferred value is [cancelled][cancel], then it becomes immediately complete and
* cancels ongoing computation coroutine if it was started.
*/
-public interface LazyDeferred<T> : Deferred<T> {
+public interface LazyDeferred<out T> : Deferred<T> {
/**
* Returns `true` if the coroutine is computing its value.
*/
@@ -41,7 +41,7 @@
* in which case the [Job] of the resulting coroutine is a child of the job of the parent coroutine.
*/
public fun <T> lazyDefer(context: CoroutineContext, block: suspend CoroutineScope.() -> T) : LazyDeferred<T> =
- LazyDeferredCoroutine<T>(newCoroutineContext(context), block).apply {
+ LazyDeferredCoroutine(newCoroutineContext(context), block).apply {
initParentJob(context[Job])
}
diff --git a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedList.kt b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedList.kt
index 2f186fd..9deaaa0 100644
--- a/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedList.kt
+++ b/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedList.kt
@@ -41,8 +41,7 @@
private fun removed(): Removed =
removedRef ?: Removed(this).also { REMOVED_REF.lazySet(this, it) }
- @PublishedApi
- internal abstract class CondAdd {
+ abstract class CondAdd {
internal lateinit var newNode: Node
internal lateinit var oldNext: Node
@Volatile
@@ -80,7 +79,7 @@
}
}
- public val isRemoved: Boolean get() = _next is Removed
+ val isRemoved: Boolean get() = _next is Removed
private val isFresh: Boolean get() = _next === this && prev === this
@@ -92,11 +91,9 @@
}
}
- @PublishedApi
- internal fun next(): Node = next.unwrap()
+ fun next(): Node = next.unwrap()
- @PublishedApi
- internal fun addFirstCC(node: Node, condAdd: CondAdd?): Boolean {
+ fun addFirstCC(node: Node, condAdd: CondAdd?): Boolean {
require(node.isFresh)
condAdd?.newNode = node
while (true) { // lock-free loop on next
@@ -111,7 +108,7 @@
}
}
- internal fun addIfEmpty(node: Node): Boolean {
+ fun addIfEmpty(node: Node): Boolean {
require(node.isFresh)
PREV.lazySet(node, this)
NEXT.lazySet(node, this)
@@ -121,8 +118,7 @@
return true
}
- @PublishedApi
- internal fun addLastCC(node: Node, condAdd: CondAdd?): Boolean {
+ fun addLastCC(node: Node, condAdd: CondAdd?): Boolean {
require(node.isFresh)
condAdd?.newNode = node
while (true) { // lock-free loop on prev.next
@@ -158,7 +154,7 @@
/**
* Removes this node from the list. Returns `true` when removed successfully.
*/
- public open fun remove(): Boolean {
+ open fun remove(): Boolean {
while (true) { // lock-free loop on next
val next = this.next
if (next is Removed) return false // was already removed -- don't try to help (original thread will take care)
@@ -171,7 +167,7 @@
}
}
- internal fun removeFirstOrNull(): Node? {
+ fun removeFirstOrNull(): Node? {
while (true) { // try to linearize
val first = next()
if (first == this) return null
@@ -260,19 +256,19 @@
private fun Any.unwrap(): Node = if (this is Removed) ref else this as Node
- internal fun validateNode(prev: Node, next: Node) {
+ fun validateNode(prev: Node, next: Node) {
check(prev === this.prev)
check(next === this.next)
}
}
internal open class LockFreeLinkedListHead : LockFreeLinkedListNode() {
- public val isEmpty: Boolean get() = next() == this
+ val isEmpty: Boolean get() = next() == this
/**
* Iterates over all elements in this list of a specified type.
*/
- public inline fun <reified T : Node> forEach(block: (T) -> Unit) {
+ inline fun <reified T : Node> forEach(block: (T) -> Unit) {
var cur: Node = next()
while (cur != this) {
if (cur is T) block(cur)
@@ -283,12 +279,12 @@
/**
* Adds first item to this list.
*/
- public fun addFirst(node: Node) { addFirstCC(node, null) }
+ fun addFirst(node: Node) { addFirstCC(node, null) }
/**
* Adds first item to this list atomically if the [condition] is true.
*/
- public inline fun addFirstIf(node: Node, crossinline condition: () -> Boolean): Boolean =
+ inline fun addFirstIf(node: Node, crossinline condition: () -> Boolean): Boolean =
addFirstCC(node, object : CondAdd() {
override fun isCondition(): Boolean = condition()
})
@@ -296,19 +292,19 @@
/**
* Adds last item to this list.
*/
- public fun addLast(node: Node) { addLastCC(node, null) }
+ fun addLast(node: Node) { addLastCC(node, null) }
/**
* Adds last item to this list atomically if the [condition] is true.
*/
- public inline fun addLastIf(node: Node, crossinline condition: () -> Boolean): Boolean =
+ inline fun addLastIf(node: Node, crossinline condition: () -> Boolean): Boolean =
addLastCC(node, object : CondAdd() {
override fun isCondition(): Boolean = condition()
})
- public override fun remove() = throw UnsupportedOperationException()
+ final override fun remove() = throw UnsupportedOperationException()
- internal fun validate() {
+ fun validate() {
var prev: Node = this
var cur: Node = next()
while (cur != this) {