kernel: remove silly drop_guard macro
This commit is contained in:
parent
fe50f8ce74
commit
c4c810744d
|
|
@ -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)() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue