Debian Codegraph @

.cargo/vendor/rustix/src/backend/libc/process/cpu_set.rs

raw
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]
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 unsafe { c::CPU_COUNT(cpuset).try_into().unwrap() }
50 }
51
52 #[inline]
53 pub(crate) fn CPU_EQUAL(this: &RawCpuSet, that: &RawCpuSet) -> bool {
54 #[cfg(any(linux_like, target_os = "fuchsia", target_os = "hurd"))]
55 unsafe {
56 c::CPU_EQUAL(this, that)
57 }
58
59 #[cfg(not(any(linux_like, target_os = "fuchsia", target_os = "hurd")))]
60 unsafe {
61 for i in 0..c::CPU_SETSIZE as usize {
62 if c::CPU_ISSET(i, this) != c::CPU_ISSET(i, that) {
63 return false;
64 }
65 }
66 true
67 }
68 }