From fad6afa7d8486e1b54f186a0bdd718113f353685 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sun, 17 Jul 2022 13:26:56 +0200 Subject: [PATCH] Flush on Drop, unless explicitly ignored. --- src/page/flush.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/page/flush.rs b/src/page/flush.rs index 5dedf6afae..1114c33bc8 100644 --- a/src/page/flush.rs +++ b/src/page/flush.rs @@ -35,9 +35,10 @@ impl PageFlush { } } -#[must_use = "The page table must be flushed, or the changes unsafely ignored"] -pub struct PageFlushAll { - phantom: PhantomData, +// TODO: Might remove Drop and add #[must_use] again, but ergonomically I prefer being able to pass +// a flusher, and have it dropped by the end of the function it is passed to, in order to flush. +pub struct PageFlushAll { + phantom: PhantomData A>, } impl PageFlushAll { @@ -47,14 +48,17 @@ impl PageFlushAll { } } - pub fn flush(self) { - unsafe { A::invalidate_all(); } - } + pub fn flush(self) {} pub unsafe fn ignore(self) { mem::forget(self); } } +impl Drop for PageFlushAll { + fn drop(&mut self) { + unsafe { A::invalidate_all(); } + } +} impl Flusher for PageFlushAll { fn consume(&mut self, flush: PageFlush) { unsafe { flush.ignore(); }