-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of a Irq_Mutex (see Issue#160) #162
base: master
Are you sure you want to change the base?
Changes from 2 commits
3663aa9
d58d055
5562c8b
6c3871b
a3b5daf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use core::arch::asm; | ||
///Contains architecture specific interrupt mask and restore code | ||
/// | ||
/// | ||
|
||
|
||
|
||
/// | ||
/// Masks all maskable interrupts and returns the previous Interrupt State | ||
#[cfg(target_arch = "x86_64")] | ||
#[inline(always)] | ||
pub(crate) fn mask_interrupts() -> bool { | ||
|
||
let mut flags: u64; | ||
unsafe{ | ||
asm!{ | ||
"pushfw", | ||
"popw {}", | ||
"cli", | ||
out(reg) flags | ||
} | ||
} | ||
|
||
//Masks of all Bits except the Interrupt Flag | ||
if flags & 0x200 > 0 { | ||
return true; | ||
} | ||
|
||
false | ||
|
||
} | ||
|
||
/// Restores the Interrupt State to its previous value | ||
#[cfg(target_arch = "x86_64")] | ||
#[inline(always)] | ||
pub(crate) fn restore_interrupts(interrupts: bool) { | ||
if interrupts { | ||
unsafe{ | ||
asm!{ | ||
"sti", | ||
"nop" //on x86_64 sti creates a Interrupt Shadow, the NOP contains this Sideeffect to the inline ASM | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth noting that if this approach is every used for a |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,25 +34,36 @@ pub mod fair; | |
#[cfg_attr(docsrs, doc(cfg(feature = "fair_mutex")))] | ||
pub use self::fair::{FairMutex, FairMutexGuard, Starvation}; | ||
|
||
#[cfg(feature = "irq_mutex")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "irq_mutex")))] | ||
pub mod interrupt; | ||
#[cfg(feature = "irq_mutex")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "spin_mutex")))] | ||
pub use self::interrupt::{IrqMutex, IrqMutexGuard}; | ||
|
||
use crate::{RelaxStrategy, Spin}; | ||
use core::{ | ||
fmt, | ||
ops::{Deref, DerefMut}, | ||
}; | ||
|
||
#[cfg(all(not(feature = "spin_mutex"), not(feature = "use_ticket_mutex")))] | ||
compile_error!("The `mutex` feature flag was used (perhaps through another feature?) without either `spin_mutex` or `use_ticket_mutex`. One of these is required."); | ||
#[cfg(all(not(feature = "spin_mutex"), not(feature = "use_ticket_mutex"), not(feature = "irq_mutex") ))] | ||
compile_error!("The `mutex` feature flag was used (perhaps through another feature?) without either `spin_mutex`, `use_ticket_mutex` or `irq_mutex`. One of these is required."); | ||
|
||
#[cfg(all(not(feature = "use_ticket_mutex"), feature = "spin_mutex"))] | ||
#[cfg(all(not(any(feature = "use_ticket_mutex", feature = "irq_mutex")), feature = "spin_mutex"))] | ||
type InnerMutex<T, R> = self::spin::SpinMutex<T, R>; | ||
#[cfg(all(not(feature = "use_ticket_mutex"), feature = "spin_mutex"))] | ||
#[cfg(all(not(any(feature = "use_ticket_mutex", feature = "irq_mutex")), feature = "spin_mutex"))] | ||
type InnerMutexGuard<'a, T> = self::spin::SpinMutexGuard<'a, T>; | ||
|
||
#[cfg(feature = "use_ticket_mutex")] | ||
#[cfg(all(not(any(feature = "irq_mutex", feature = "spin_mutex")), feature = "use_ticket_mutex"))] | ||
type InnerMutex<T, R> = self::ticket::TicketMutex<T, R>; | ||
#[cfg(feature = "use_ticket_mutex")] | ||
#[cfg(all(not(any(feature = "irq_mutex", feature = "spin_mutex")), feature = "use_ticket_mutex"))] | ||
type InnerMutexGuard<'a, T> = self::ticket::TicketMutexGuard<'a, T>; | ||
|
||
#[cfg(all(not(any(feature = "use_ticket_mutex", feature = "spin_mutex")), feature = "irq_mutex"))] | ||
type InnerMutex<T, R> = self::interrupt::IrqMutex<T, R>; | ||
#[cfg(all(not(any(feature = "use_ticket_mutex", feature = "spin_mutex")), feature = "irq_mutex"))] | ||
type InnerMutexGuard<'a, T> = self::interrupt::IrqMutexGuard<'a, T>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that the IRQ mutex should be used as the default implementation. Spin mutexes are supported on every platform, and are still useful on those platforms (even and perhaps especially embedded platforms), and the IRQ mutex has different behaviour to the other mutexes when invoked in an interrupt. For this reason, it should just be its own stand-alone mutex and never accidentally the default implementation. |
||
/// A spin-based lock providing mutually exclusive access to data. | ||
/// | ||
/// The implementation uses either a ticket mutex or a regular spin mutex depending on whether the `spin_mutex` or | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't portable, I think the
critical-section
crate should be used instead.