Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/instructions/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Enabling and disabling interrupts

use core::arch::asm;
use core::sync::atomic::{compiler_fence, Ordering};

/// Returns whether interrupts are enabled.
#[inline]
Expand All @@ -16,10 +15,10 @@ pub fn are_enabled() -> bool {
/// This is a wrapper around the `sti` instruction.
#[inline]
pub fn enable() {
// Prevent earlier writes to be moved beyond this point
compiler_fence(Ordering::Release);
// Omit `nomem` to imitate a lock release. Otherwise, the compiler
// is free to move reads and writes through this asm block.
unsafe {
asm!("sti", options(nomem, nostack));
asm!("sti", options(preserves_flags, nostack));
}
}

Expand All @@ -28,10 +27,10 @@ pub fn enable() {
/// This is a wrapper around the `cli` instruction.
#[inline]
pub fn disable() {
// Prevent future writes to be moved before this point.
compiler_fence(Ordering::Acquire);
// Omit `nomem` to imitate a lock acquire. Otherwise, the compiler
// is free to move reads and writes through this asm block.
unsafe {
asm!("cli", options(nomem, nostack));
asm!("cli", options(preserves_flags, nostack));
}
}

Expand Down