From 7a8f0688bdb3ebade23658c6b46861e6ce2f4da4 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Tue, 6 Jan 2026 21:16:47 +0800 Subject: [PATCH] chore: use Vec instead of Slab to store waiting wakers in WaitSet --- mea/src/internal/waitset.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mea/src/internal/waitset.rs b/mea/src/internal/waitset.rs index d57096f..d0d5be6 100644 --- a/mea/src/internal/waitset.rs +++ b/mea/src/internal/waitset.rs @@ -15,31 +15,29 @@ use std::task::Context; use std::task::Waker; -use slab::Slab; - #[derive(Debug)] pub(crate) struct WaitSet { - waiters: Slab, + waiters: Vec, } impl WaitSet { /// Construct a new, empty wait set. pub const fn new() -> Self { Self { - waiters: Slab::new(), + waiters: Vec::new(), } } /// Construct a new, empty wait set with the specified capacity. pub fn with_capacity(capacity: usize) -> Self { Self { - waiters: Slab::with_capacity(capacity), + waiters: Vec::with_capacity(capacity), } } /// Drain and wake up all waiters. pub(crate) fn wake_all(&mut self) { - for w in self.waiters.drain() { + for w in self.waiters.drain(..) { w.wake(); } } @@ -51,11 +49,11 @@ impl WaitSet { pub(crate) fn register_waker(&mut self, idx: &mut Option, cx: &mut Context<'_>) { match *idx { None => { - let key = self.waiters.insert(cx.waker().clone()); - *idx = Some(key); + self.waiters.push(cx.waker().clone()); + *idx = Some(self.waiters.len() - 1); } Some(key) => { - if self.waiters.contains(key) { + if key < self.waiters.len() { if !self.waiters[key].will_wake(cx.waker()) { self.waiters[key] = cx.waker().clone(); } @@ -71,8 +69,8 @@ impl WaitSet { // // Barrier holds the lock during check and register, so the race condition // above won't happen. - let key = self.waiters.insert(cx.waker().clone()); - *idx = Some(key); + self.waiters.push(cx.waker().clone()); + *idx = Some(self.waiters.len() - 1); } } }