浏览代码

perf(mpsc): remove panics from wait queue (#50)

The wait queue should never panic in release mode.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Eliza Weisman 3 年之前
父节点
当前提交
f61993f0e5
共有 1 个文件被更改,包括 13 次插入6 次删除
  1. 13 6
      src/wait/queue.rs

+ 13 - 6
src/wait/queue.rs

@@ -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.
@@ -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.