-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
runtime: improve safety comments of Readiness<'_>
#7415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
runtime: improve safety comments of Readiness<'_>
#7415
Conversation
tokio/src/runtime/io/scheduled_io.rs
Outdated
let (scheduled_io, state, waiter) = { | ||
// Safety: `Self` is `!Unpin` | ||
let me = unsafe { self.get_unchecked_mut() }; | ||
(me.scheduled_io, &mut me.state, &me.waiter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reviewers: The reason I didn't use pin_project
to eliminate the unsafe
block is that Future
's implementation already has a lot of unsafe
blocks, so eliminating it doesn't significantly reduce the mental burden but increases code complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take it or leave it: perhaps that's worth including in the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokio/src/runtime/io/scheduled_io.rs
Outdated
// Safety: We don't need to acquire the lock here because | ||
// the `waiter.interest` never changes. | ||
let interest = unsafe { (*waiter.get()).interest }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be shared in this scenario? You removed the comment that says it can't - is that because it actually can or just because you don't need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be shared in this scenario?
The State::Done
certainly indicates waiter
is not shared, the original comment is right.
is that because it actually can or just because you don't need it?
Because the original comment is not comprehensive.
waiter.interest
is not shared in this scenario, but this doesn't mean we can always observe the latest value of waiter.interest
without the lock held, unless waiter.interest
is never changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have enriched the safety comment for your concern: af0a52a .
tokio/src/runtime/io/scheduled_io.rs
Outdated
let (scheduled_io, state, waiter) = { | ||
// Safety: `Self` is `!Unpin` | ||
let me = unsafe { self.get_unchecked_mut() }; | ||
(me.scheduled_io, &mut me.state, &me.waiter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take it or leave it: perhaps that's worth including in the comment?
029df9f
to
b8c9124
Compare
Signed-off-by: ADD-SP <[email protected]>
Signed-off-by: ADD-SP <[email protected]>
Signed-off-by: ADD-SP <[email protected]> Co-authored-by: Eliza Weisman <[email protected]>
b8c9124
to
6e6b73e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to merge with below grammar fixed.
// Safety: Since the `waiter` is not in the intrusive list yet, | ||
// so we have exclusive access to it. The Mutex ensures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentences starting with "since" don't use "so".
// Safety: Since the `waiter` is not in the intrusive list yet, | |
// so we have exclusive access to it. The Mutex ensures | |
// Safety: Since the `waiter` is not in the intrusive list yet, | |
// we have exclusive access to it. The Mutex ensures |
Motivation
Just some improvements while reading the source.
Solution
Nothing to point out in particular.