Add a page flusher trait.
This commit is contained in:
+17
-4
@@ -8,6 +8,10 @@ use crate::{
|
||||
VirtualAddress,
|
||||
};
|
||||
|
||||
pub trait Flusher<A> {
|
||||
fn consume(&mut self, flush: PageFlush<A>);
|
||||
}
|
||||
|
||||
#[must_use = "The page table must be flushed, or the changes unsafely ignored"]
|
||||
pub struct PageFlush<A> {
|
||||
virt: VirtualAddress,
|
||||
@@ -43,10 +47,6 @@ impl <A: Arch> PageFlushAll<A> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn consume(&self, flush: PageFlush<A>) {
|
||||
unsafe { flush.ignore(); }
|
||||
}
|
||||
|
||||
pub fn flush(self) {
|
||||
unsafe { A::invalidate_all(); }
|
||||
}
|
||||
@@ -55,3 +55,16 @@ impl <A: Arch> PageFlushAll<A> {
|
||||
mem::forget(self);
|
||||
}
|
||||
}
|
||||
impl<A: Arch> Flusher<A> for PageFlushAll<A> {
|
||||
fn consume(&mut self, flush: PageFlush<A>) {
|
||||
unsafe { flush.ignore(); }
|
||||
}
|
||||
}
|
||||
impl<A: Arch, T: Flusher<A> + ?Sized> Flusher<A> for &mut T {
|
||||
fn consume(&mut self, flush: PageFlush<A>) {
|
||||
<T as Flusher<A>>::consume(self, flush)
|
||||
}
|
||||
}
|
||||
impl<A: Arch> Flusher<A> for () {
|
||||
fn consume(&mut self, _: PageFlush<A>) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user