Skip to content

Commit d30366f

Browse files
committed
Dispatch: correct DispatchTimeInterval calculation on ASi
There is no guarantee that Mach ticks and nanoseconds have a 1:1 relationship. Use the `uptimeNanoseconds` field which will convert the raw value (which is in Mach ticks) to the time unit of nanoseconds. This was caught by the Dispatch stridable test in the Swift test suite. rdar://problem/56623421
1 parent a422bfb commit d30366f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stdlib/public/Darwin/Dispatch/Schedulers+DispatchQueue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ extension DispatchTime /* : Strideable */ {
4545
typealias Stride = DispatchTimeInterval
4646

4747
public func distance(to other: DispatchTime) -> DispatchTimeInterval {
48-
let lhs = other.rawValue
49-
let rhs = rawValue
48+
let lhs = other.uptimeNanoseconds
49+
let rhs = uptimeNanoseconds
5050
if lhs >= rhs {
5151
return DispatchTimeInterval.nanoseconds(Int(lhs - rhs))
5252
} else {

0 commit comments

Comments
 (0)