Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tokio/src/sync/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,11 @@ impl NotifiedProject<'_> {
State::Init => {
let curr = notify.state.load(SeqCst);

if get_num_notify_waiters_calls(curr) != *notify_waiters_calls {
*state = State::Done;
continue 'outer_loop;
}

// Optimistically try acquiring a pending notification
let res = notify.state.compare_exchange(
set_state(curr, NOTIFIED),
Expand Down
12 changes: 12 additions & 0 deletions tokio/tests/sync_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,15 @@ fn test_waker_update() {

assert!(future.is_woken());
}

#[test]
fn notify_one_has_priority_over_notify_waiters() {
use futures::FutureExt;
let notify = tokio::sync::Notify::new();
let notified1 = notify.notified();
notify.notify_waiters();
notify.notify_one();
assert!(notified1.now_or_never().is_some());
let notified2 = notify.notified();
assert!(notified2.now_or_never().is_some());
}
Loading