#critical-section #spin-lock #synchronization #arceos #no-irq

no-std kspin

Spinlocks used for kernel space that can disable preemption or IRQs in the critical section

1 unstable release

0.1.0 Jul 17, 2024

#373 in Operating systems

Download history 214/week @ 2024-07-13 378/week @ 2024-07-20 598/week @ 2024-07-27 184/week @ 2024-08-03 235/week @ 2024-08-10 161/week @ 2024-08-17 177/week @ 2024-08-24 323/week @ 2024-08-31 506/week @ 2024-09-07 323/week @ 2024-09-14 317/week @ 2024-09-21 166/week @ 2024-09-28 480/week @ 2024-10-05 1114/week @ 2024-10-12 884/week @ 2024-10-19 378/week @ 2024-10-26

2,874 downloads per month

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

17KB
302 lines

kspin

Crates.io Docs.rs CI

Spinlocks used for kernel space that can disable preemption or IRQs in the critical section.

Cargo Features

  • smp: Use in the multi-core environment. For single-core environment (without this feature), the lock state is unnecessary and optimized out. CPU can always get the lock if we follow the proper guard in use. By default, this feature is disabled.

Examples

use kspin::{SpinNoIrq, SpinNoPreempt, SpinRaw};

let data = SpinRaw::new(());
let mut guard = data.lock();
/* critical section, does nothing while trying to lock. */
drop(guard);

let data = SpinNoPreempt::new(());
let mut guard = data.lock();
/* critical section, preemption are disabled. */
drop(guard);

let data = SpinNoIrq::new(());
let mut guard = data.lock();
/* critical section, both preemption and IRQs are disabled. */
drop(guard);

Dependencies

~270–720KB
~17K SLoC