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]
|
||||
macro_rules! drop_guard {
|
||||
($($stmts:stmt)*) => {
|
||||
{
|
||||
struct __DropGuard<F: FnOnce()>(::core::mem::ManuallyDrop<F>);
|
||||
|
||||
impl<F: FnOnce()> __DropGuard<F> {
|
||||
#[allow(dead_code)]
|
||||
fn forget(self) {
|
||||
let mut this = ::core::mem::ManuallyDrop::new(self);
|
||||
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)*
|
||||
}))
|
||||
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)]
|
||||
pub fn forget(self) {
|
||||
let mut this = ::core::mem::ManuallyDrop::new(self);
|
||||
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)() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue