Provide specialized TimeSource.Monotonic for Native
KT-46132
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,7 +9,18 @@ import kotlin.system.*
|
|||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
@ExperimentalTime
|
@ExperimentalTime
|
||||||
internal actual object MonotonicTimeSource : AbstractLongTimeSource(unit = DurationUnit.NANOSECONDS), TimeSource { // TODO: interface should not be required here
|
internal actual object MonotonicTimeSource : TimeSource {
|
||||||
override fun read(): Long = getTimeNanos()
|
private val zero: Long = getTimeNanos()
|
||||||
override fun toString(): String = "TimeSource(nanoTime())"
|
private fun read(): Long = getTimeNanos() - zero
|
||||||
}
|
override fun toString(): String = "TimeSource(System.nanoTime())"
|
||||||
|
|
||||||
|
actual override fun markNow(): DefaultTimeMark = DefaultTimeMark(read())
|
||||||
|
actual fun elapsedFrom(timeMark: DefaultTimeMark): Duration =
|
||||||
|
saturatingDiff(read(), timeMark.reading)
|
||||||
|
|
||||||
|
actual fun adjustReading(timeMark: DefaultTimeMark, duration: Duration): DefaultTimeMark =
|
||||||
|
DefaultTimeMark(saturatingAdd(timeMark.reading, duration))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("ACTUAL_WITHOUT_EXPECT") // visibility
|
||||||
|
internal actual typealias DefaultTimeMarkReading = Long
|
||||||
|
|||||||
Reference in New Issue
Block a user