]>
Commit | Line | Data |
---|---|---|
fe692bf9 FG |
1 | //! Rust implementation of the `CPU_*` macro API. |
2 | ||
3 | #![allow(non_snake_case)] | |
4 | ||
5 | use super::super::c; | |
6 | use super::types::{RawCpuSet, CPU_SETSIZE}; | |
7 | ||
8 | #[inline] | |
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] | |
20 | pub(crate) fn CPU_ZERO(cpuset: &mut RawCpuSet) { | |
21 | unsafe { c::CPU_ZERO(cpuset) } | |
22 | } | |
23 | ||
24 | #[inline] | |
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] | |
36 | 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] | |
48 | pub(crate) fn CPU_COUNT(cpuset: &RawCpuSet) -> u32 { | |
49 | use core::convert::TryInto; | |
50 | unsafe { c::CPU_COUNT(cpuset).try_into().unwrap() } | |
51 | } |