Skip to content

Commit 803596d

Browse files
committed
add closure to run a function with interruption
1 parent 264e511 commit 803596d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/collections/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2020 Stefan Lankes, RWTH Aachen University
2+
//
3+
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4+
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5+
// http://opensource.org/licenses/MIT>, at your option. This file may not be
6+
// copied, modified, or distributed except according to those terms.
7+
8+
use crate::arch::irq::*;
9+
10+
/// `irqsave` guarantees that the call of the closure
11+
/// will be not disturbed by an interrupt
12+
#[inline]
13+
pub fn irqsave<F, R>(f: F) -> R
14+
where
15+
F: FnOnce() -> R,
16+
{
17+
let irq = irq_nested_disable();
18+
let ret = f();
19+
irq_nested_enable(irq);
20+
ret
21+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod macros;
2929
#[macro_use]
3030
pub mod logging;
3131
pub mod arch;
32+
pub mod collections;
3233
pub mod console;
3334
pub mod consts;
3435
pub mod errno;

0 commit comments

Comments
 (0)