Re: [PATCH v6 1/3] rust: Introduce irq module
From: Trevor Gross
Date: Sun Sep 29 2024 - 16:36:54 EST
On Mon, Sep 16, 2024 at 5:31 PM Lyude Paul <lyude@xxxxxxxxxx> wrote:
>
> This introduces a module for dealing with interrupt-disabled contexts,
> including the ability to enable and disable interrupts
> (with_irqs_disabled()) - along with the ability to annotate functions as
> expecting that IRQs are already disabled on the local CPU.
>
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
> Reviewed-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
> Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
> +impl IrqDisabled<'_> {
> + /// Create a new [`IrqDisabled`] token in an interrupt disabled context.
> + ///
> + /// This creates an [`IrqDisabled`] token, which can be passed to functions that must be run
> + /// without interrupts. If debug assertions are enabled, this function will assert that
> + /// interrupts are disabled upon creation. Otherwise, it has no size or cost at runtime.
> + ///
> + /// # Panics
> + ///
> + /// If debug assertions are enabled, this function will panic if interrupts are not disabled
> + /// upon creation.
> + ///
> + /// # Safety
> + ///
> + /// This function must only be called in contexts where it is already known that interrupts have
> + /// been disabled for the current CPU, and the user is making a promise that they will remain
> + /// disabled at least until this [`IrqDisabled`] is dropped.
> + pub unsafe fn new() -> Self {
It could be worth mentioning that you probably won't be calling this
function directly if you need an IrqDisabled, linking to
with_irqs_disabled instead.
Either way this looks great!
Reviewed-by: Trevor Gross <tmgross@xxxxxxxxx>