@@ -13,40 +13,40 @@ import kotlin.jvm.*
13
13
private val UNDEFINED = Symbol (" UNDEFINED" )
14
14
15
15
/* *
16
- * Executes given [block] as part of current event loop, updating related to block [ continuation]
16
+ * Executes given [block] as part of current event loop, updating current continuation
17
17
* mode and state if continuation is not resumed immediately.
18
18
* [doYield] indicates whether current continuation is yielding (to provide fast-path if event-loop is empty).
19
19
* Returns `true` if execution of continuation was queued (trampolined) or `false` otherwise.
20
20
*/
21
- private inline fun executeUnconfined (
22
- continuation : DispatchedContinuation < * >, contState : Any? , mode : Int ,
23
- doYield : Boolean = false, block : () -> Unit
21
+ private inline fun DispatchedContinuation < * >. executeUnconfined (
22
+ contState : Any? , mode : Int , doYield : Boolean = false ,
23
+ block : () -> Unit
24
24
) : Boolean {
25
25
val eventLoop = ThreadLocalEventLoop .eventLoop
26
26
// If we are yielding and unconfined queue is empty, we can bail out as part of fast path
27
27
if (doYield && eventLoop.isEmptyUnconfinedQueue) return false
28
28
return if (eventLoop.isUnconfinedLoopActive) {
29
29
// When unconfined loop is active -- dispatch continuation for execution to avoid stack overflow
30
- continuation. _state = contState
31
- continuation. resumeMode = mode
32
- eventLoop.dispatchUnconfined(continuation )
30
+ _state = contState
31
+ resumeMode = mode
32
+ eventLoop.dispatchUnconfined(this )
33
33
true // queued into the active loop
34
34
} else {
35
- // Was not active -- run event loop until unconfined tasks are executed
35
+ // Was not active -- run event loop until all unconfined tasks are executed
36
36
runUnconfinedEventLoop(eventLoop, block = block)
37
37
false
38
38
}
39
39
}
40
40
41
- private fun resumeUnconfined ( task : DispatchedTask <* >) {
41
+ private fun DispatchedTask <* >. resumeUnconfined ( ) {
42
42
val eventLoop = ThreadLocalEventLoop .eventLoop
43
43
if (eventLoop.isUnconfinedLoopActive) {
44
44
// When unconfined loop is active -- dispatch continuation for execution to avoid stack overflow
45
- eventLoop.dispatchUnconfined(task )
45
+ eventLoop.dispatchUnconfined(this )
46
46
} else {
47
- // Was not active -- run event loop until unconfined tasks are executed
47
+ // Was not active -- run event loop until all unconfined tasks are executed
48
48
runUnconfinedEventLoop(eventLoop) {
49
- task. resume(task. delegate, MODE_UNDISPATCHED )
49
+ resume(delegate, MODE_UNDISPATCHED )
50
50
}
51
51
}
52
52
}
@@ -103,7 +103,7 @@ internal class DispatchedContinuation<in T>(
103
103
resumeMode = MODE_ATOMIC_DEFAULT
104
104
dispatcher.dispatch(context, this )
105
105
} else {
106
- executeUnconfined(this , state, MODE_ATOMIC_DEFAULT ) {
106
+ executeUnconfined(state, MODE_ATOMIC_DEFAULT ) {
107
107
withCoroutineContext(this .context, countOrElement) {
108
108
continuation.resumeWith(result)
109
109
}
@@ -118,7 +118,7 @@ internal class DispatchedContinuation<in T>(
118
118
resumeMode = MODE_CANCELLABLE
119
119
dispatcher.dispatch(context, this )
120
120
} else {
121
- executeUnconfined(this , value, MODE_CANCELLABLE ) {
121
+ executeUnconfined(value, MODE_CANCELLABLE ) {
122
122
if (! resumeCancelled()) {
123
123
resumeUndispatched(value)
124
124
}
@@ -135,7 +135,7 @@ internal class DispatchedContinuation<in T>(
135
135
resumeMode = MODE_CANCELLABLE
136
136
dispatcher.dispatch(context, this )
137
137
} else {
138
- executeUnconfined(this , state, MODE_CANCELLABLE ) {
138
+ executeUnconfined(state, MODE_CANCELLABLE ) {
139
139
if (! resumeCancelled()) {
140
140
resumeUndispatchedWithException(exception)
141
141
}
@@ -259,7 +259,7 @@ internal abstract class DispatchedTask<in T>(
259
259
}
260
260
261
261
internal fun DispatchedContinuation<Unit>.yieldUndispatched (): Boolean =
262
- executeUnconfined(this , Unit , MODE_CANCELLABLE , doYield = true ) {
262
+ executeUnconfined(Unit , MODE_CANCELLABLE , doYield = true ) {
263
263
run ()
264
264
}
265
265
@@ -272,7 +272,7 @@ internal fun <T> DispatchedTask<T>.dispatch(mode: Int = MODE_CANCELLABLE) {
272
272
if (dispatcher.isDispatchNeeded(context)) {
273
273
dispatcher.dispatch(context, this )
274
274
} else {
275
- resumeUnconfined(this )
275
+ resumeUnconfined()
276
276
}
277
277
} else {
278
278
resume(delegate, mode)
0 commit comments