1 #![allow(non_snake_case)]
2
3 use super::types::RawCpuSet;
4 use core::mem::size_of_val;
5
6 #[inline]
CPU_SET(cpu: usize, cpuset: &mut RawCpuSet)7 pub(crate) fn CPU_SET(cpu: usize, cpuset: &mut RawCpuSet) {
8 let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
9 let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
10 cpuset.bits[idx] |= 1 << offset
11 }
12
13 #[inline]
CPU_ZERO(cpuset: &mut RawCpuSet)14 pub(crate) fn CPU_ZERO(cpuset: &mut RawCpuSet) {
15 // TODO: With, Rust 1.50, use `cpuset.bits.fill(0)` instead.
16 for element in &mut cpuset.bits {
17 *element = 0;
18 }
19 }
20
21 #[inline]
CPU_CLR(cpu: usize, cpuset: &mut RawCpuSet)22 pub(crate) fn CPU_CLR(cpu: usize, cpuset: &mut RawCpuSet) {
23 let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
24 let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
25 cpuset.bits[idx] &= !(1 << offset)
26 }
27
28 #[inline]
CPU_ISSET(cpu: usize, cpuset: &RawCpuSet) -> bool29 pub(crate) fn CPU_ISSET(cpu: usize, cpuset: &RawCpuSet) -> bool {
30 let size_in_bits = 8 * size_of_val(&cpuset.bits[0]);
31 let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
32 (cpuset.bits[idx] & (1 << offset)) != 0
33 }
34
35 #[inline]
CPU_COUNT_S(size_in_bytes: usize, cpuset: &RawCpuSet) -> u3236 pub(crate) fn CPU_COUNT_S(size_in_bytes: usize, cpuset: &RawCpuSet) -> u32 {
37 let size_of_mask = size_of_val(&cpuset.bits[0]);
38 let idx = size_in_bytes / size_of_mask;
39 cpuset.bits[..idx]
40 .iter()
41 .fold(0, |acc, i| acc + i.count_ones())
42 }
43
44 #[inline]
CPU_COUNT(cpuset: &RawCpuSet) -> u3245 pub(crate) fn CPU_COUNT(cpuset: &RawCpuSet) -> u32 {
46 CPU_COUNT_S(core::mem::size_of::<RawCpuSet>(), cpuset)
47 }
48