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

#414 in Operating systems

Download history 151/week @ 2024-07-12 328/week @ 2024-07-19 503/week @ 2024-07-26 390/week @ 2024-08-02 236/week @ 2024-08-09 149/week @ 2024-08-16 178/week @ 2024-08-23 306/week @ 2024-08-30 519/week @ 2024-09-06 285/week @ 2024-09-13 354/week @ 2024-09-20 179/week @ 2024-09-27 397/week @ 2024-10-04

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

~235–670KB
~16K SLoC