Struct rp6::avr::interrupt::CriticalSection
source · pub struct CriticalSection(PhantomData<()>);
Expand description
Helper struct that automatically restores interrupts on drop. The wrapped PhantomData
creates
a private field to ensure that this struct cannot be initialized from outside of this module
without using its unsafe
initializer function new
. The recommended use to enter a
CriticalSection
is to pass a closure to without_interrupts
.
When the feature unsafe-no-critical-section-count
is disabled, this implementation is also
safe w.r.t. nested calls of without_interrupts
. This is achieved by counting how many
CriticalSection
s were entered, and only enabling device interrupts once the last
CriticalSection
is exited. However, as these checks incur a small runtime overhead, they can
be disabled with the feature unsafe-no-critical-section-count
. Note that, for execution
consistency, a user must then ensure that without_interrupts
will never be nested!
Tuple Fields§
§0: PhantomData<()>
Implementations§
source§impl CriticalSection
impl CriticalSection
sourcepub unsafe fn new() -> Self
pub unsafe fn new() -> Self
Upon entering any CriticalSection
, disable global device interrupts.
Safety
When the feature unsafe-no-critical-section-count
is disabled, this implementation is also
safe w.r.t. nested CriticalSection
s, e.g., by nesting calls to without_interrupts
. This
is achieved by counting how many CriticalSection
s were entered, and only enabling device
interrupts once the last CriticalSection
is exited. However, as these checks incur a small
runtime overhead, they can be disabled with the feature unsafe-no-critical-section-count
.
Note that, for execution consistency, a user must then ensure that CriticalSection
s will
never be nested!