#critical-section #preemption #synchronization #arceos #wrapper

nightly no-std kernel_guard

RAII wrappers to create a critical section with local IRQs or preemption disabled

2 releases

0.1.1 Jul 11, 2024
0.1.0 May 9, 2023

#771 in Operating systems

Download history 214/week @ 2024-08-14 295/week @ 2024-08-21 233/week @ 2024-08-28 460/week @ 2024-09-04 437/week @ 2024-09-11 450/week @ 2024-09-18 378/week @ 2024-09-25 183/week @ 2024-10-02 873/week @ 2024-10-09 1436/week @ 2024-10-16 668/week @ 2024-10-23 284/week @ 2024-10-30 202/week @ 2024-11-06 375/week @ 2024-11-13 547/week @ 2024-11-20 442/week @ 2024-11-27

1,577 downloads per month
Used in 2 crates

GPL-3.0-or-later OR Apache-2…

12KB
174 lines

kernel_guard

Crates.io

RAII wrappers to create a critical section with local IRQs or preemption disabled, used to implement spin locks in kernel.

The critical section is created after the guard struct is created, and is ended when the guard falls out of scope.

The crate user must implement the KernelGuardIf trait using crate_interface::impl_interface to provide the low-level implementantion of how to enable/disable kernel preemption, if the feature preempt is enabled.

Available guards:

  • NoOp: Does nothing around the critical section.
  • IrqSave: Disables/enables local IRQs around the critical section.
  • NoPreempt: Disables/enables kernel preemption around the critical section.
  • NoPreemptIrqSave: Disables/enables both kernel preemption and local IRQs around the critical section.

Crate features

  • preempt: Use in the preemptive system. If this feature is enabled, you need to implement the KernelGuardIf trait in other crates. Otherwise the preemption enable/disable operations will be no-ops. This feature is disabled by default.

Examples

use kernel_guard::{KernelGuardIf, NoPreempt};

struct KernelGuardIfImpl;

#[crate_interface::impl_interface]
impl KernelGuardIf for KernelGuardIfImpl {
    fn enable_preempt() {
        // Your implementation here
    }
    fn disable_preempt() {
        // Your implementation here
    }
}

let guard = NoPreempt::new();
/* The critical section starts here

Do something that requires preemption to be disabled

The critical section ends here */
drop(guard);

Dependencies

~225–670KB
~16K SLoC