@@ -36,7 +36,7 @@ internal abstract class EventLoop : CoroutineDispatcher() {
36
36
* Queue used by [Dispatchers.Unconfined] tasks.
37
37
* These tasks are thread-local for performance and take precedence over the rest of the queue.
38
38
*/
39
- private var unconfinedQueue: ArrayQueue <DispatchedTask <* >>? = null
39
+ private var unconfinedQueue: ArrayDeque <DispatchedTask <* >>? = null
40
40
41
41
/* *
42
42
* Processes next event in this event loop.
@@ -49,7 +49,7 @@ internal abstract class EventLoop : CoroutineDispatcher() {
49
49
* **NOTE**: Must be invoked only from the event loop's thread
50
50
* (no check for performance reasons, may be added in the future).
51
51
*/
52
- public open fun processNextEvent (): Long {
52
+ open fun processNextEvent (): Long {
53
53
if (! processUnconfinedEvent()) return Long .MAX_VALUE
54
54
return 0
55
55
}
@@ -59,10 +59,10 @@ internal abstract class EventLoop : CoroutineDispatcher() {
59
59
protected open val nextTime: Long
60
60
get() {
61
61
val queue = unconfinedQueue ? : return Long .MAX_VALUE
62
- return if (queue.isEmpty) Long .MAX_VALUE else 0L
62
+ return if (queue.isEmpty() ) Long .MAX_VALUE else 0L
63
63
}
64
64
65
- public fun processUnconfinedEvent (): Boolean {
65
+ fun processUnconfinedEvent (): Boolean {
66
66
val queue = unconfinedQueue ? : return false
67
67
val task = queue.removeFirstOrNull() ? : return false
68
68
task.run ()
@@ -74,27 +74,27 @@ internal abstract class EventLoop : CoroutineDispatcher() {
74
74
* By default, event loop implementation is thread-local and should not processed in the context
75
75
* (current thread's event loop should be processed instead).
76
76
*/
77
- public open fun shouldBeProcessedFromContext (): Boolean = false
77
+ open fun shouldBeProcessedFromContext (): Boolean = false
78
78
79
79
/* *
80
80
* Dispatches task whose dispatcher returned `false` from [CoroutineDispatcher.isDispatchNeeded]
81
81
* into the current event loop.
82
82
*/
83
- public fun dispatchUnconfined (task : DispatchedTask <* >) {
83
+ fun dispatchUnconfined (task : DispatchedTask <* >) {
84
84
val queue = unconfinedQueue ? :
85
- ArrayQueue <DispatchedTask <* >>().also { unconfinedQueue = it }
85
+ ArrayDeque <DispatchedTask <* >>().also { unconfinedQueue = it }
86
86
queue.addLast(task)
87
87
}
88
88
89
- public val isActive: Boolean
89
+ val isActive: Boolean
90
90
get() = useCount > 0
91
91
92
- public val isUnconfinedLoopActive: Boolean
92
+ val isUnconfinedLoopActive: Boolean
93
93
get() = useCount >= delta(unconfined = true )
94
94
95
95
// May only be used from the event loop's thread
96
- public val isUnconfinedQueueEmpty: Boolean
97
- get() = unconfinedQueue?.isEmpty ? : true
96
+ val isUnconfinedQueueEmpty: Boolean
97
+ get() = unconfinedQueue?.isEmpty() ? : true
98
98
99
99
private fun delta (unconfined : Boolean ) =
100
100
if (unconfined) (1L shl 32 ) else 1L
@@ -200,7 +200,7 @@ internal abstract class EventLoopImplBase: EventLoopImplPlatform(), Delay {
200
200
}
201
201
}
202
202
203
- protected override val nextTime: Long
203
+ override val nextTime: Long
204
204
get() {
205
205
if (super .nextTime == 0L ) return 0L
206
206
val queue = _queue .value
@@ -227,7 +227,7 @@ internal abstract class EventLoopImplBase: EventLoopImplPlatform(), Delay {
227
227
rescheduleAllDelayed()
228
228
}
229
229
230
- public override fun scheduleResumeAfterDelay (timeMillis : Long , continuation : CancellableContinuation <Unit >) {
230
+ override fun scheduleResumeAfterDelay (timeMillis : Long , continuation : CancellableContinuation <Unit >) {
231
231
val timeNanos = delayToNanos(timeMillis)
232
232
if (timeNanos < MAX_DELAY_NS ) {
233
233
val now = nanoTime()
@@ -283,7 +283,7 @@ internal abstract class EventLoopImplBase: EventLoopImplPlatform(), Delay {
283
283
return nextTime
284
284
}
285
285
286
- public final override fun dispatch (context : CoroutineContext , block : Runnable ) = enqueue(block)
286
+ final override fun dispatch (context : CoroutineContext , block : Runnable ) = enqueue(block)
287
287
288
288
open fun enqueue (task : Runnable ) {
289
289
if (enqueueImpl(task)) {
@@ -362,7 +362,7 @@ internal abstract class EventLoopImplBase: EventLoopImplPlatform(), Delay {
362
362
363
363
}
364
364
365
- public fun schedule (now : Long , delayedTask : DelayedTask ) {
365
+ fun schedule (now : Long , delayedTask : DelayedTask ) {
366
366
when (scheduleImpl(now, delayedTask)) {
367
367
SCHEDULE_OK -> if (shouldUnpark(delayedTask)) unpark()
368
368
SCHEDULE_COMPLETED -> reschedule(now, delayedTask)
@@ -481,7 +481,6 @@ internal abstract class EventLoopImplBase: EventLoopImplPlatform(), Delay {
481
481
final override fun dispose () {
482
482
val heap = _heap
483
483
if (heap == = DISPOSED_TASK ) return // already disposed
484
- @Suppress(" UNCHECKED_CAST" )
485
484
(heap as ? DelayedTaskQueue )?.remove(this ) // remove if it is in heap (first)
486
485
_heap = DISPOSED_TASK // never add again to any heap
487
486
}
@@ -530,7 +529,7 @@ internal expect fun createEventLoop(): EventLoop
530
529
internal expect fun nanoTime (): Long
531
530
532
531
internal expect object DefaultExecutor {
533
- public fun enqueue (task : Runnable )
532
+ fun enqueue (task : Runnable )
534
533
}
535
534
536
535
/* *
0 commit comments