From 2f16dddf25ba3acabd253118f05a38e9edb6091d Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Mon, 4 Jul 2022 10:41:53 +0200
Subject: [PATCH] Add a page flusher trait.
---
src/page/flush.rs | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/page/flush.rs b/src/page/flush.rs
index 9aae51f599..5dedf6afae 100644
--- a/src/page/flush.rs
+++ b/src/page/flush.rs
@@ -8,6 +8,10 @@ use crate::{
VirtualAddress,
};
+pub trait Flusher {
+ fn consume(&mut self, flush: PageFlush);
+}
+
#[must_use = "The page table must be flushed, or the changes unsafely ignored"]
pub struct PageFlush {
virt: VirtualAddress,
@@ -43,10 +47,6 @@ impl PageFlushAll {
}
}
- pub fn consume(&self, flush: PageFlush) {
- unsafe { flush.ignore(); }
- }
-
pub fn flush(self) {
unsafe { A::invalidate_all(); }
}
@@ -55,3 +55,16 @@ impl PageFlushAll {
mem::forget(self);
}
}
+impl Flusher for PageFlushAll {
+ fn consume(&mut self, flush: PageFlush) {
+ unsafe { flush.ignore(); }
+ }
+}
+impl + ?Sized> Flusher for &mut T {
+ fn consume(&mut self, flush: PageFlush) {
+ >::consume(self, flush)
+ }
+}
+impl Flusher for () {
+ fn consume(&mut self, _: PageFlush) {}
+}