2
2
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- @file:Suppress(" INVISIBLE_REFERENCE" , " INVISIBLE_MEMBER" )
6
-
7
5
package kotlinx.coroutines
8
6
9
7
import kotlinx.coroutines.internal.*
10
8
import kotlinx.coroutines.scheduling.*
11
9
import kotlin.coroutines.*
12
10
import kotlin.coroutines.jvm.internal.*
11
+ import kotlin.coroutines.jvm.internal.CoroutineStackFrame
13
12
14
13
internal const val COROUTINES_SCHEDULER_PROPERTY_NAME = " kotlinx.coroutines.scheduler"
15
14
@@ -58,7 +57,7 @@ internal actual inline fun <T> withContinuationContext(continuation: Continuatio
58
57
val oldValue = updateThreadContext(context, countOrElement)
59
58
val undispatchedCompletion = if (oldValue != = NO_THREAD_ELEMENTS ) {
60
59
// Only if some values were replaced we'll go to the slow path of figuring out where/how to restore them
61
- continuation.undispatchedCompletion()
60
+ ( continuation as ? CoroutineStackFrame )? .undispatchedCompletion()
62
61
} else
63
62
null // fast path -- don't even try to find undispatchedCompletion as there's nothing to restore in the context
64
63
undispatchedCompletion?.saveThreadContext(context, oldValue)
@@ -70,16 +69,14 @@ internal actual inline fun <T> withContinuationContext(continuation: Continuatio
70
69
}
71
70
}
72
71
73
- internal tailrec fun Continuation < * > .undispatchedCompletion (): UndispatchedCoroutine <* >? {
72
+ internal tailrec fun CoroutineStackFrame .undispatchedCompletion (): UndispatchedCoroutine <* >? {
74
73
// Find direct completion of this continuation
75
- val completion: Continuation <* > = when (this ) {
76
- is BaseContinuationImpl -> completion ? : return null // regular suspending function -- direct resume
77
- is DispatchedCoroutine -> return null // dispatches on resume
78
- is ScopeCoroutine -> uCont // other scoped coroutine -- direct resume
79
- else -> return null // something else -- not supported
74
+ val completion: CoroutineStackFrame ? = when (this ) {
75
+ is DispatchedCoroutine <* > -> return null // dispatches on resume
76
+ else -> callerFrame ? : return null // something else -- not supported
80
77
}
81
78
if (completion is UndispatchedCoroutine <* >) return completion // found UndispatchedCoroutine!
82
- return completion.undispatchedCompletion() // walk up the call stack with tail call
79
+ return completion? .undispatchedCompletion() // walk up the call stack with tail call
83
80
}
84
81
85
82
// Used by withContext when context changes, but dispatcher stays the same
0 commit comments