ruduino/src/prelude.rs

27 lines
505 B
Rust
Raw Normal View History

2016-07-06 23:59:51 +00:00
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()
}