Skip to content

Commit

Permalink
perf(mpsc): remove panics from wait queue (#50)
Browse files Browse the repository at this point in the history
The wait queue should never panic in release mode.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw authored Mar 16, 2022
1 parent 8d34b1c commit f61993f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/wait/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ impl<T: Notify + Unpin> WaitQueue<T> {
debug_assert!(actual == EMPTY || actual == WAKING);
self.state.store(WAKING, SeqCst);
}
false
}
WAITING => {
let waiter = list.dequeue(WAKING);
debug_assert!(waiter.is_some(), "if we were in the `WAITING` state, there must be a waiter in the queue!\nself={:#?}", self);
debug_assert!(
waiter.is_some(),
"if we were in the `WAITING` state, there must be a waiter in the queue!\nself={:#?}",
self,
);

// If we popped the last node, transition back to the empty
// state.
Expand All @@ -421,13 +424,17 @@ impl<T: Notify + Unpin> WaitQueue<T> {
// wake the waiter
if let Some(waiter) = waiter {
waiter.notify();
true
} else {
false
return true;
}
}
weird => unreachable!("notify_slow: unexpected state value {:?}", weird),
_weird => {
// huh, if `notify_slow` was called, we *probably* shouldn't be
// in the `closed` state...
#[cfg(debug_assertions)]
unreachable!("notify_slow: unexpected state value {:?}", _weird);
}
}
false
}

/// Close the queue, notifying all waiting tasks.
Expand Down

0 comments on commit f61993f

Please sign in to comment.