Commit 59ffa72d authored by Stefan Lankes's avatar Stefan Lankes Committed by Stefan Lankes
Browse files

add help function, which disables interrupts during the runtime of a closure

parent 85be907a
...@@ -13,6 +13,16 @@ mod doublylinkedlist; ...@@ -13,6 +13,16 @@ mod doublylinkedlist;
pub use self::cachepadded::*; pub use self::cachepadded::*;
pub use self::doublylinkedlist::*; pub use self::doublylinkedlist::*;
/// `irqsave` guarantees that the call of the closure
/// will be not disturbed by an interrupt
#[inline]
pub fn irqsave<F: FnMut()>(mut f: F) where F: FnOnce() {
let irq = irq::nested_disable();
f();
irq::nested_enable(irq);
}
/// Help structure to disable interrupts as long as this data structure exists
pub struct AvoidInterrupts(bool); pub struct AvoidInterrupts(bool);
impl AvoidInterrupts { impl AvoidInterrupts {
......
...@@ -16,7 +16,7 @@ use crate::arch; ...@@ -16,7 +16,7 @@ use crate::arch;
use crate::arch::irq; use crate::arch::irq;
use crate::arch::percore::*; use crate::arch::percore::*;
use crate::arch::{switch_to_fpu_owner, switch_to_task}; use crate::arch::{switch_to_fpu_owner, switch_to_task};
use crate::collections::AvoidInterrupts; use crate::collections::{irqsave, AvoidInterrupts};
use crate::config::*; use crate::config::*;
use crate::scheduler::task::*; use crate::scheduler::task::*;
use crate::synch::spinlock::*; use crate::synch::spinlock::*;
...@@ -116,9 +116,7 @@ impl PerCoreScheduler { ...@@ -116,9 +116,7 @@ impl PerCoreScheduler {
/// Terminate the current task on the current core. /// Terminate the current task on the current core.
pub fn exit(&mut self, exit_code: i32) -> ! { pub fn exit(&mut self, exit_code: i32) -> ! {
{ let closure = || {
let _ = AvoidInterrupts::new();
// Get the current task. // Get the current task.
let mut current_task_borrowed = self.current_task.borrow_mut(); let mut current_task_borrowed = self.current_task.borrow_mut();
assert_ne!( assert_ne!(
...@@ -134,7 +132,9 @@ impl PerCoreScheduler { ...@@ -134,7 +132,9 @@ impl PerCoreScheduler {
); );
current_task_borrowed.status = TaskStatus::TaskFinished; current_task_borrowed.status = TaskStatus::TaskFinished;
NO_TASKS.fetch_sub(1, Ordering::SeqCst); NO_TASKS.fetch_sub(1, Ordering::SeqCst);
} };
irqsave(closure);
self.scheduler(); self.scheduler();
...@@ -207,14 +207,14 @@ impl PerCoreScheduler { ...@@ -207,14 +207,14 @@ impl PerCoreScheduler {
#[inline] #[inline]
pub fn handle_waiting_tasks(&mut self) { pub fn handle_waiting_tasks(&mut self) {
let _ = AvoidInterrupts::new(); let closure = || { self.blocked_tasks.handle_waiting_tasks() };
self.blocked_tasks.handle_waiting_tasks(); irqsave(closure);
} }
pub fn custom_wakeup(&mut self, task: TaskHandle) { pub fn custom_wakeup(&mut self, task: TaskHandle) {
if task.get_core_id() == self.core_id { if task.get_core_id() == self.core_id {
let _ = AvoidInterrupts::new(); let closure = || { self.blocked_tasks.custom_wakeup(task) };
self.blocked_tasks.custom_wakeup(task); irqsave(closure);
} else { } else {
get_scheduler(task.get_core_id()) get_scheduler(task.get_core_id())
.input .input
...@@ -228,9 +228,8 @@ impl PerCoreScheduler { ...@@ -228,9 +228,8 @@ impl PerCoreScheduler {
#[inline] #[inline]
pub fn block_current_task(&mut self, wakeup_time: Option<u64>) { pub fn block_current_task(&mut self, wakeup_time: Option<u64>) {
let _ = AvoidInterrupts::new(); let closure = || { self.blocked_tasks.add(self.current_task.clone(), wakeup_time)};
self.blocked_tasks irqsave(closure);
.add(self.current_task.clone(), wakeup_time);
} }
#[inline] #[inline]
...@@ -248,15 +247,16 @@ impl PerCoreScheduler { ...@@ -248,15 +247,16 @@ impl PerCoreScheduler {
#[cfg(feature = "newlib")] #[cfg(feature = "newlib")]
#[inline] #[inline]
pub fn set_lwip_errno(&self, errno: i32) { pub fn set_lwip_errno(&self, errno: i32) {
let _ = AvoidInterrupts::new(); let closure = || { self.current_task.borrow_mut().lwip_errno = errno };
self.current_task.borrow_mut().lwip_errno = errno;
irqsave(closure);
} }
#[cfg(feature = "newlib")] #[cfg(feature = "newlib")]
#[inline] #[inline]
pub fn get_lwip_errno(&self) -> i32 { pub fn get_lwip_errno(&self) -> i32 {
let _ = AvoidInterrupts::new(); let closure = || { self.current_task.borrow().lwip_errno };
self.current_task.borrow().lwip_errno irqsave(closure);
} }
#[inline] #[inline]
...@@ -279,8 +279,8 @@ impl PerCoreScheduler { ...@@ -279,8 +279,8 @@ impl PerCoreScheduler {
#[inline] #[inline]
pub fn set_current_task_wakeup_reason(&mut self, reason: WakeupReason) { pub fn set_current_task_wakeup_reason(&mut self, reason: WakeupReason) {
let _ = AvoidInterrupts::new(); let closure = || { self.current_task.borrow_mut().last_wakeup_reason = reason };
self.current_task.borrow_mut().last_wakeup_reason = reason; irqsave(closure);
} }
#[inline] #[inline]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment