Fixes incorrect implementation of DispatchTime.init(uptimeNanoseconds:) #7432
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Internally, DispatchTime works in Mach absolute time, but the DispatchTime(uptimeNanoseconds:) initializer allows time to be given as nanoseconds since boot. This needs to be converted to Mach absolute time, but the conversion was not being performed. As a result, on platforms where the conversion factor is not 1, the wrong time is stored.
The fix is to convert the given time to Mach absolute time when the conversion factor is not 1. This may cause some loss of precision, so the uptimeNanoseconds property will not hold the same value as the one passed to the initializer, unless that value was an exact multiple of the conversion factor. One way to fix this would be to store both the actual value that was given and the converted value. However, dispatch does not use the original value and keeping it would add another field to the DispatchTime object, just on the off-chance that the application might want the exact initial value. Instead of saving the actual value, I added a comment to the initializer to indicate that the value read from the uptimeNanoseconds property will be the effective value, which might be rounded up from the original.
(Radar 29660448)
rdar://problem/29660448