• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines
6 
7 import kotlin.coroutines.*
8 import kotlin.native.concurrent.*
9 import kotlin.system.*
10 
11 internal actual abstract class EventLoopImplPlatform : EventLoop() {
12 
13     private val current = Worker.current
14 
unparknull15     protected actual fun unpark() {
16         current.executeAfter(0L, {})// send an empty task to unpark the waiting event loop
17     }
18 
reschedulenull19     protected actual fun reschedule(now: Long, delayedTask: EventLoopImplBase.DelayedTask) {
20         DefaultExecutor.invokeOnTimeout(now, delayedTask, EmptyCoroutineContext)
21     }
22 }
23 
24 internal class EventLoopImpl: EventLoopImplBase() {
invokeOnTimeoutnull25     override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle =
26         DefaultDelay.invokeOnTimeout(timeMillis, block, context)
27 }
28 
29 internal actual fun createEventLoop(): EventLoop = EventLoopImpl()
30 
31 internal actual fun nanoTime(): Long = getTimeNanos()
32