Commits (2)
use core::mem;
use core::sync::atomic::AtomicBool;
use core::sync::atomic::{AtomicBool, Ordering};
use syscall::data::FloatRegisters;
/// This must be used by the kernel to ensure that context switches are done atomically
......@@ -127,6 +127,7 @@ impl Context {
}
/// Switch to the next context by restoring its stack and registers
/// Check disassembly!
#[cold]
#[inline(never)]
#[naked]
......@@ -167,6 +168,9 @@ impl Context {
asm!("mov $0, rbp" : "=r"(self.rbp) : : "memory" : "intel", "volatile");
asm!("mov rbp, $0" : : "r"(next.rbp) : "memory" : "intel", "volatile");
// Unset global lock after loading registers but before switch
CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
}
}
......
......@@ -135,11 +135,9 @@ pub unsafe fn switch() -> bool {
CONTEXT_ID.store((*to_ptr).id, Ordering::SeqCst);
}
// Unset global lock before switch, as arch is only usable by the current CPU at this time
arch::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
if to_ptr as usize == 0 {
// No target was found, return
// No target was found, unset global lock and return
arch::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
false
} else {
......