diff --git a/src/sync/mod.rs b/src/sync/mod.rs index f4ece62255..74a79956e7 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1,5 +1,4 @@ -pub use self::{wait_condition::WaitCondition, wait_map::WaitMap, wait_queue::WaitQueue}; +pub use self::{wait_condition::WaitCondition, wait_queue::WaitQueue}; pub mod wait_condition; -pub mod wait_map; pub mod wait_queue; diff --git a/src/sync/wait_map.rs b/src/sync/wait_map.rs deleted file mode 100644 index 5d0468e741..0000000000 --- a/src/sync/wait_map.rs +++ /dev/null @@ -1,72 +0,0 @@ -use alloc::collections::BTreeMap; -use core::mem; -use spin::Mutex; - -use crate::sync::WaitCondition; - -#[derive(Debug)] -pub struct WaitMap { - // Using BTreeMap as this depends on .keys() providing elements in sorted order. - pub inner: Mutex>, - pub condition: WaitCondition, -} - -impl WaitMap -where - K: Clone + Ord, -{ - pub fn new() -> WaitMap { - WaitMap { - inner: Mutex::new(BTreeMap::new()), - condition: WaitCondition::new(), - } - } - - pub fn receive_nonblock(&self, key: &K) -> Option { - self.inner.lock().remove(key) - } - - pub fn receive(&self, key: &K, reason: &'static str) -> Option { - loop { - let mut inner = self.inner.lock(); - if let Some(value) = inner.remove(key) { - return Some(value); - } - if !self.condition.wait(inner, reason) { - return None; - } - } - } - - pub fn receive_any_nonblock(&self) -> Option<(K, V)> { - let mut inner = self.inner.lock(); - if let Some(key) = inner.keys().next().cloned() { - inner.remove(&key).map(|value| (key, value)) - } else { - None - } - } - - pub fn receive_any(&self, reason: &'static str) -> (K, V) { - loop { - let mut inner = self.inner.lock(); - if let Some(key) = inner.keys().next().cloned() { - if let Some(entry) = inner.remove(&key).map(|value| (key, value)) { - return entry; - } - } - let _ = self.condition.wait(inner, reason); - } - } - - pub fn receive_all(&self) -> BTreeMap { - let mut ret = BTreeMap::new(); - mem::swap(&mut ret, &mut *self.inner.lock()); - ret - } - - pub fn send(&self, key: K, value: V) { - self.inner.lock().insert(key, value); - self.condition.notify(); - } -}