use crate::storage::StorageId;
use alloc::collections::BTreeSet;
#[derive(Debug)]
pub struct MemoryLock {
locked: BTreeSet<StorageId>,
flush_threshold: usize,
}
impl MemoryLock {
pub fn new(flush_threshold: usize) -> Self {
Self {
locked: Default::default(),
flush_threshold,
}
}
pub fn is_locked(&self, storage: &StorageId) -> bool {
self.locked.contains(storage)
}
pub fn has_reached_threshold(&self) -> bool {
self.locked.len() >= self.flush_threshold
}
pub fn add_locked(&mut self, storage: StorageId) {
self.locked.insert(storage);
}
pub fn clear_locked(&mut self) {
self.locked.clear();
}
}