time: small implementation cleanups#6517
Merged
Merged
Conversation
`StateCell::mark_pending` already uses a loop to retry the compare exchange operation if it fails. The logic within the loop would handle a spurious failure like any other failure, so `compare_exchange_weak` makes the implementation more efficient for some platforms.
This replaces a manual implementation of
`Instant::saturating_duration_since` with the actual one.
Clippy already catches this for primitive integer types via the
`manual_saturating_arithmetic` lint, as demonstrated by the following
example:
```rs
fn saturating_sub(val: usize, n: usize) -> usize {
val.checked_sub(n).unwrap_or(0)
}
```
As explained by the comment removed by this commit earlier Rust versions didn't have an ergonomic way of building arrays of any size of non-Copy types. Rust 1.63 stabilized `array::from_fn`, fixing the above issue and by making it easy to construct arrays from a constructor.
This replaces `Wheel::levels`, currently represented as a `Vec` of 6 elements, into an array. This should help eliminate some bounds checks from accesses to `levels`. This changes the size of `Wheel` from 48 bytes to 32 bytes on x86_64. The initial implementation didn't Box the array, resulting into `Wheel` having a size of 6264 bytes and loom tests overflowing their stack.
Replaces the manual implementation of a waker list with `WakeList`.
Member
|
cc @wathenjiang |
Contributor
|
All LGTM! However, it should be pointed out that in the current implementation, the behavior of I think we should ensure that the order of this FIFO remains unchanged. |
Contributor
Author
Good catch! I've opened a separate PR to fix it #6521 |
Member
|
Order of wakers is generally not something we guarantee, but I think having |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
While reading how the timer driver works, I found several things that could be cleaned up.
Solution
I've included those fixes in this PR.