kernel: remove silly drop_guard macro

This commit is contained in:
janis 2026-08-02 16:12:12 +02:00
parent fe50f8ce74
commit c4c810744d
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8
2 changed files with 19 additions and 28 deletions

View file

@ -41,31 +41,22 @@ pub unsafe fn volatile_copy<T: Sized>(src: *const T, dst: *mut T, count: usize)
} }
} }
#[macro_export] pub struct DropGuard<F: FnOnce()>(::core::mem::ManuallyDrop<F>);
macro_rules! drop_guard { impl<F: FnOnce()> DropGuard<F> {
($($stmts:stmt)*) => { pub fn new(f: F) -> Self {
{ DropGuard(::core::mem::ManuallyDrop::new(f))
struct __DropGuard<F: FnOnce()>(::core::mem::ManuallyDrop<F>); }
#[allow(dead_code)]
impl<F: FnOnce()> __DropGuard<F> { pub fn forget(self) {
#[allow(dead_code)] let mut this = ::core::mem::ManuallyDrop::new(self);
fn forget(self) { unsafe {
let mut this = ::core::mem::ManuallyDrop::new(self); ::core::mem::ManuallyDrop::drop(&mut this.0);
unsafe {
::core::mem::ManuallyDrop::drop(&mut this.0);
}
}
}
impl<F: FnOnce()> Drop for __DropGuard<F> {
fn drop(&mut self) {
unsafe { ::core::ptr::read(&*self.0)() }
}
}
__DropGuard(::core::mem::ManuallyDrop::new(|| {
$($stmts)*
}))
} }
}; }
}
impl<F: FnOnce()> Drop for DropGuard<F> {
fn drop(&mut self) {
unsafe { ::core::ptr::read(&*self.0)() }
}
} }

View file

@ -210,9 +210,9 @@ mod once {
// even though we don't have unwinding, for // even though we don't have unwinding, for
// completeness sake we'll poison the lock if // completeness sake we'll poison the lock if
// the closure panics. // the closure panics.
let guard = crate::drop_guard! { let guard = crate::DropGuard::new(|| {
self.state.store(POISONED, Ordering::Release) self.state.store(POISONED, Ordering::Release)
}; });
let state = OnceState { let state = OnceState {
poisoned: state == POISONED, poisoned: state == POISONED,