1 //! Rust implementation of the `CPU_*` macro API.
2 
3 #![allow(non_snake_case)]
4 
5 use super::types::{RawCpuSet, CPU_SETSIZE};
6 use crate::backend::c;
7 
8 #[inline]
CPU_SET(cpu: usize, cpuset: &mut RawCpuSet)9 pub(crate) fn CPU_SET(cpu: usize, cpuset: &mut RawCpuSet) {
10     assert!(
11         cpu < CPU_SETSIZE,
12         "cpu out of bounds: the cpu max is {} but the cpu is {}",
13         CPU_SETSIZE,
14         cpu
15     );
16     unsafe { c::CPU_SET(cpu, cpuset) }
17 }
18 
19 #[inline]
CPU_ZERO(cpuset: &mut RawCpuSet)20 pub(crate) fn CPU_ZERO(cpuset: &mut RawCpuSet) {
21     unsafe { c::CPU_ZERO(cpuset) }
22 }
23 
24 #[inline]
CPU_CLR(cpu: usize, cpuset: &mut RawCpuSet)25 pub(crate) fn CPU_CLR(cpu: usize, cpuset: &mut RawCpuSet) {
26     assert!(
27         cpu < CPU_SETSIZE,
28         "cpu out of bounds: the cpu max is {} but the cpu is {}",
29         CPU_SETSIZE,
30         cpu
31     );
32     unsafe { c::CPU_CLR(cpu, cpuset) }
33 }
34 
35 #[inline]
CPU_ISSET(cpu: usize, cpuset: &RawCpuSet) -> bool36 pub(crate) fn CPU_ISSET(cpu: usize, cpuset: &RawCpuSet) -> bool {
37     assert!(
38         cpu < CPU_SETSIZE,
39         "cpu out of bounds: the cpu max is {} but the cpu is {}",
40         CPU_SETSIZE,
41         cpu
42     );
43     unsafe { c::CPU_ISSET(cpu, cpuset) }
44 }
45 
46 #[cfg(linux_kernel)]
47 #[inline]
CPU_COUNT(cpuset: &RawCpuSet) -> u3248 pub(crate) fn CPU_COUNT(cpuset: &RawCpuSet) -> u32 {
49     unsafe { c::CPU_COUNT(cpuset).try_into().unwrap() }
50 }
51