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
sync: Remove readiness assertion in `watch::Receiver::changed() #2839
Merged
carllerche
merged 3 commits into
tokio-rs:master
from
zaharidichev:zd/handle-lost-notifications
Sep 22, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -105,6 +105,13 @@ pub struct Notify { | |||||||||||||||||
state: AtomicU8, | ||||||||||||||||||
waiters: Mutex<WaitList>, | ||||||||||||||||||
} | ||||||||||||||||||
#[derive(Debug, Clone, Copy)] | ||||||||||||||||||
enum NotificationType { | ||||||||||||||||||
// Notification trigerred by calling `notify_waiters` | ||||||||||||||||||
AllWaiters, | ||||||||||||||||||
// Notification trigerred by calling `notify_one` | ||||||||||||||||||
OneWaiter, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typos:
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#[derive(Debug)] | ||||||||||||||||||
struct Waiter { | ||||||||||||||||||
|
@@ -115,7 +122,7 @@ struct Waiter { | |||||||||||||||||
waker: Option<Waker>, | ||||||||||||||||||
|
||||||||||||||||||
/// `true` if the notification has been assigned to this waiter. | ||||||||||||||||||
notified: bool, | ||||||||||||||||||
notified: Option<NotificationType>, | ||||||||||||||||||
|
||||||||||||||||||
/// Should not be `Unpin`. | ||||||||||||||||||
_p: PhantomPinned, | ||||||||||||||||||
|
@@ -230,7 +237,7 @@ impl Notify { | |||||||||||||||||
waiter: UnsafeCell::new(Waiter { | ||||||||||||||||||
pointers: linked_list::Pointers::new(), | ||||||||||||||||||
waker: None, | ||||||||||||||||||
notified: false, | ||||||||||||||||||
notified: None, | ||||||||||||||||||
_p: PhantomPinned, | ||||||||||||||||||
}), | ||||||||||||||||||
} | ||||||||||||||||||
|
@@ -327,9 +334,9 @@ impl Notify { | |||||||||||||||||
// Safety: `waiters` lock is still held. | ||||||||||||||||||
let waiter = unsafe { waiter.as_mut() }; | ||||||||||||||||||
|
||||||||||||||||||
assert!(!waiter.notified); | ||||||||||||||||||
assert!(waiter.notified.is_none()); | ||||||||||||||||||
|
||||||||||||||||||
waiter.notified = true; | ||||||||||||||||||
waiter.notified = Some(NotificationType::AllWaiters); | ||||||||||||||||||
|
||||||||||||||||||
if let Some(waker) = waiter.waker.take() { | ||||||||||||||||||
waker.wake(); | ||||||||||||||||||
|
@@ -375,9 +382,9 @@ fn notify_locked(waiters: &mut WaitList, state: &AtomicU8, curr: u8) -> Option<W | |||||||||||||||||
// Safety: `waiters` lock is still held. | ||||||||||||||||||
let waiter = unsafe { waiter.as_mut() }; | ||||||||||||||||||
|
||||||||||||||||||
assert!(!waiter.notified); | ||||||||||||||||||
assert!(waiter.notified.is_none()); | ||||||||||||||||||
|
||||||||||||||||||
waiter.notified = true; | ||||||||||||||||||
waiter.notified = Some(NotificationType::OneWaiter); | ||||||||||||||||||
let waker = waiter.waker.take(); | ||||||||||||||||||
|
||||||||||||||||||
if waiters.is_empty() { | ||||||||||||||||||
|
@@ -506,11 +513,11 @@ impl Future for Notified<'_> { | |||||||||||||||||
// Safety: called while locked | ||||||||||||||||||
let w = unsafe { &mut *waiter.get() }; | ||||||||||||||||||
|
||||||||||||||||||
if w.notified { | ||||||||||||||||||
if w.notified.is_some() { | ||||||||||||||||||
// Our waker has been notified. Reset the fields and | ||||||||||||||||||
// remove it from the list. | ||||||||||||||||||
w.waker = None; | ||||||||||||||||||
w.notified = false; | ||||||||||||||||||
w.notified = None; | ||||||||||||||||||
|
||||||||||||||||||
*state = Done; | ||||||||||||||||||
} else { | ||||||||||||||||||
|
@@ -583,13 +590,12 @@ impl Drop for Notified<'_> { | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// See if the node was notified but not received. In this case, the | ||||||||||||||||||
// notification must be sent to another waiter. | ||||||||||||||||||
// notification must be sent to another waiter, only if it was | ||||||||||||||||||
// triggered via `notify_one` | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might rephrase this to something like // See if the node was notified but not received. In this case, if
// the notification was triggered via `notify_one`, it must be sent
// to the next waiter. |
||||||||||||||||||
// | ||||||||||||||||||
// Safety: with the entry removed from the linked list, there can be | ||||||||||||||||||
// no concurrent access to the entry | ||||||||||||||||||
let notified = unsafe { (*waiter.get()).notified }; | ||||||||||||||||||
|
||||||||||||||||||
if notified { | ||||||||||||||||||
if let Some(NotificationType::OneWaiter) = unsafe { (*waiter.get()).notified } { | ||||||||||||||||||
if let Some(waker) = notify_locked(&mut waiters, ¬ify.state, notify_state) { | ||||||||||||||||||
drop(waiters); | ||||||||||||||||||
waker.wake(); | ||||||||||||||||||
|
This file contains 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
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.
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.
nit: i'd add a newline here (surprised that rustfmt doesn't do that?)