#spin-lock #synchronization #critical-section #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

#424 in Operating systems

Download history 394/week @ 2024-08-01 199/week @ 2024-08-08 192/week @ 2024-08-15 181/week @ 2024-08-22 302/week @ 2024-08-29 521/week @ 2024-09-05 256/week @ 2024-09-12 314/week @ 2024-09-19 243/week @ 2024-09-26 268/week @ 2024-10-03 862/week @ 2024-10-10 1192/week @ 2024-10-17 538/week @ 2024-10-24 85/week @ 2024-10-31 268/week @ 2024-11-07 409/week @ 2024-11-14

1,439 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

~245–690KB
~16K SLoC