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

View file

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