mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add a Locked wrapper type that can be used to implement GlobalAlloc
This commit is contained in:
@@ -54,3 +54,20 @@ unsafe impl GlobalAlloc for Dummy {
|
|||||||
panic!("dealloc should be never called")
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user