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::cpu::CpuId;
use kernel::cpumask::CpumaskVar;
let mut mask = CpumaskVar::new_zero(GFP_KERNEL).unwrap();
assert!(mask.empty());
let mut count = 0;
let cpu2 = CpuId::from_u32(2);
if let Some(cpu) = cpu2 {
mask.set(cpu);
assert!(mask.test(cpu));
count += 1;
}
let cpu3 = CpuId::from_u32(3);
if let Some(cpu) = cpu3 {
mask.set(cpu);
assert!(mask.test(cpu));
count += 1;
}
assert_eq!(mask.weight(), count);
let mask2 = CpumaskVar::try_clone(&mask).unwrap();
if let Some(cpu) = cpu2 {
assert!(mask2.test(cpu));
}
if let Some(cpu) = cpu3 {
assert!(mask2.test(cpu));
}
assert_eq!(mask2.weight(), count);
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: CpuId)
pub fn set(&mut self, cpu: CpuId)
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: CpuId)
pub fn clear(&mut self, cpu: CpuId)
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: CpuId) -> bool
pub fn test(&self, cpu: CpuId) -> 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.
Trait Implementations§
Source§impl Deref for CpumaskVar
impl Deref for CpumaskVar
Source§impl DerefMut for CpumaskVar
impl DerefMut for CpumaskVar
Auto Trait Implementations§
impl Freeze for CpumaskVar
impl !RefUnwindSafe for CpumaskVar
impl !Send for CpumaskVar
impl !Sync for CpumaskVar
impl Unpin for CpumaskVar
impl !UnwindSafe for CpumaskVar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot
. Read more