From 55c87c801a84a30b31aae0464287afc460cecc3b Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 16 Mar 2022 10:24:44 -0700 Subject: [PATCH] perf(mpsc): remove panics from wait queue The wait queue should never panic in release mode. Signed-off-by: Eliza Weisman --- src/wait/queue.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/wait/queue.rs b/src/wait/queue.rs index d66fe0e..0a4f454 100644 --- a/src/wait/queue.rs +++ b/src/wait/queue.rs @@ -403,11 +403,14 @@ impl WaitQueue { 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. @@ -421,13 +424,17 @@ impl WaitQueue { // 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.