1 unstable release

0.1.0 Oct 13, 2024

#400 in No standard library

Download history 669/week @ 2025-08-06 1246/week @ 2025-08-13 1113/week @ 2025-08-20 862/week @ 2025-08-27 1142/week @ 2025-09-03 709/week @ 2025-09-10 486/week @ 2025-09-17 995/week @ 2025-09-24 119/week @ 2025-10-01 538/week @ 2025-10-08 373/week @ 2025-10-15 345/week @ 2025-10-22 546/week @ 2025-10-29 644/week @ 2025-11-05 918/week @ 2025-11-12 794/week @ 2025-11-19

3,014 downloads per month

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

17KB
398 lines

cpumask

Crates.io Docs.rs CI

CPU mask library

Cpumasks provide a bitmap suitable for representing the set of CPUs in a system, one bit position per CPU number. In general, only nr_cpu_ids (<= NR_CPUS) bits are valid. Refering to cpumask_t in Linux. Reference:

Examples

use cpumask::CpuMask;
const SMP: usize = 32;

let mut cpumask = CpuMask::<SMP>::new();

assert!(cpumask.is_empty());
cpumask.set(0, true);

assert!(!cpumask.is_empty());
assert!(cpumask.get(0));
assert_eq!(cpumask.len(), 1);

assert!(!cpumask.set(1, true));
assert_eq!(cpumask.len(), 2);
assert_eq!(cpumask.first_false_index(), Some(2));

let mut oneshot = CpuMask::<SMP>::one_shot(SMP - 1);
assert!(!oneshot.is_empty());
assert!(oneshot.get(SMP - 1));
assert_eq!(oneshot.first_index(), Some(SMP - 1));
assert_eq!(oneshot.len(), 1);

oneshot.set(0, false);
assert!(!oneshot.is_empty());
oneshot.set(SMP - 1, false);
assert!(oneshot.is_empty());
assert_eq!(oneshot.len(), 0);
assert_eq!(oneshot.first_index(), None);

let mut cpumask_full = CpuMask::<SMP>::full();
assert_eq!(cpumask_full.len(), SMP);
assert_eq!(cpumask_full.first_index(), Some(0));
assert_eq!(cpumask_full.first_false_index(), None);
cpumask_full.set(SMP-1, false);
assert_eq!(cpumask_full.len(), SMP - 1);
assert_eq!(cpumask_full.first_false_index(), Some(SMP-1));

Dependencies

~72KB