Add a Locked wrapper type that can be used to implement GlobalAlloc

This commit is contained in:
Philipp Oppermann
2020-01-09 15:34:04 +01:00
parent 7c84dbaa1d
commit 08d2289dad

View File

@@ -54,3 +54,20 @@ unsafe impl GlobalAlloc for Dummy {
panic!("dealloc should be never called")
}
}
/// A wrapper around spin::Mutex to permit trait implementations.
pub struct Locked<A> {
inner: spin::Mutex<A>,
}
impl<A> Locked<A> {
pub const fn new(inner: A) -> Self {
Locked {
inner: spin::Mutex::new(inner),
}
}
pub fn lock(&self) -> spin::MutexGuard<A> {
self.inner.lock()
}
}