mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
f250ad7b40
add rw locks usage
26 lines
674 B
Swift
26 lines
674 B
Swift
// Copyright 2018 Yandex LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
public typealias Milliseconds = Int64
|
|
public typealias Nanoseconds = Int64
|
|
public typealias UNanoseconds = UInt64
|
|
|
|
extension TimeInterval {
|
|
public var milliseconds: Milliseconds {
|
|
let ms = self * 1000
|
|
return Milliseconds(ms.rounded())
|
|
}
|
|
|
|
public var nanoseconds: Nanoseconds {
|
|
let nsecs = self * 1_000_000_000
|
|
let bottomBounded = max(nsecs, 0)
|
|
let topBounded = min(bottomBounded, TimeInterval(Nanoseconds.max))
|
|
return Nanoseconds(topBounded)
|
|
}
|
|
|
|
public static func from(nanoseconds: Nanoseconds) -> Self {
|
|
TimeInterval(nanoseconds) / TimeInterval(NSEC_PER_SEC)
|
|
}
|
|
}
|