pub struct CpumaskVar { /* private fields */ }
Expand description
A CPU Mask pointer.
Rust abstraction for the C struct cpumask_var_t
.
§Invariants
A CpumaskVar
instance always corresponds to a valid C struct cpumask_var_t
.
The callers must ensure that the struct cpumask_var_t
is valid for access and remains valid
for the lifetime of CpumaskVar
.
§Examples
The following example demonstrates how to create and update a CpumaskVar
.
use kernel::cpumask::CpumaskVar;
let mut mask = CpumaskVar::new_zero(GFP_KERNEL).unwrap();
assert!(mask.empty());
mask.set(2);
assert!(mask.test(2));
mask.set(3);
assert!(mask.test(3));
assert_eq!(mask.weight(), 2);
let mask2 = CpumaskVar::try_clone(&mask).unwrap();
assert!(mask2.test(2));
assert!(mask2.test(3));
assert_eq!(mask2.weight(), 2);
Implementations§
Source§impl CpumaskVar
impl CpumaskVar
Sourcepub fn new_zero(_flags: Flags) -> Result<Self, AllocError>
pub fn new_zero(_flags: Flags) -> Result<Self, AllocError>
Creates a zero-initialized instance of the CpumaskVar
.
Sourcepub unsafe fn new(_flags: Flags) -> Result<Self, AllocError>
pub unsafe fn new(_flags: Flags) -> Result<Self, AllocError>
Creates an instance of the CpumaskVar
.
§Safety
The caller must ensure that the returned CpumaskVar
is properly initialized before
getting used.
Sourcepub unsafe fn as_mut_ref<'a>(ptr: *mut cpumask_var_t) -> &'a mut Self
pub unsafe fn as_mut_ref<'a>(ptr: *mut cpumask_var_t) -> &'a mut Self
Creates a mutable reference to an existing struct cpumask_var_t
pointer.
§Safety
The caller must ensure that ptr
is valid for writing and remains valid for the lifetime
of the returned reference.
Methods from Deref<Target = Cpumask>§
Sourcepub fn set(&mut self, cpu: u32)
pub fn set(&mut self, cpu: u32)
Set cpu
in the cpumask.
ATTENTION: Contrary to C, this Rust set()
method is non-atomic.
This mismatches kernel naming convention and corresponds to the C
function __cpumask_set_cpu()
.
Sourcepub fn clear(&mut self, cpu: i32)
pub fn clear(&mut self, cpu: i32)
Clear cpu
in the cpumask.
ATTENTION: Contrary to C, this Rust clear()
method is non-atomic.
This mismatches kernel naming convention and corresponds to the C
function __cpumask_clear_cpu()
.
Sourcepub fn test(&self, cpu: i32) -> bool
pub fn test(&self, cpu: i32) -> bool
Test cpu
in the cpumask.
Equivalent to the kernel’s cpumask_test_cpu
API.
Sourcepub fn setall(&mut self)
pub fn setall(&mut self)
Set all CPUs in the cpumask.
Equivalent to the kernel’s cpumask_setall
API.
Sourcepub fn empty(&self) -> bool
pub fn empty(&self) -> bool
Checks if cpumask is empty.
Equivalent to the kernel’s cpumask_empty
API.
Sourcepub fn full(&self) -> bool
pub fn full(&self) -> bool
Checks if cpumask is full.
Equivalent to the kernel’s cpumask_full
API.