27 lines
505 B
Rust
27 lines
505 B
Rust
|
use core::prelude::v1::*;
|
||
|
use core::marker::PhantomData;
|
||
|
|
||
|
pub struct DisableInterrupts(PhantomData<()>);
|
||
|
|
||
|
impl DisableInterrupts {
|
||
|
#[inline]
|
||
|
pub fn new() -> DisableInterrupts {
|
||
|
unsafe { asm!("CLI") }
|
||
|
DisableInterrupts(PhantomData)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Drop for DisableInterrupts {
|
||
|
#[inline]
|
||
|
fn drop(&mut self) {
|
||
|
unsafe { asm!("SEI") }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn without_interrupts<F, T>(f: F) -> T
|
||
|
where F: FnOnce() -> T
|
||
|
{
|
||
|
let _disabled = DisableInterrupts::new();
|
||
|
f()
|
||
|
}
|