pub struct Cpumask(/* private fields */);
Expand description
A CPU Mask.
Rust abstraction for the C struct cpumask
.
§Invariants
A Cpumask
instance always corresponds to a valid C struct cpumask
.
The callers must ensure that the struct cpumask
is valid for access and
remains valid for the lifetime of the returned reference.
§Examples
The following example demonstrates how to update a Cpumask
.
use kernel::bindings;
use kernel::cpumask::Cpumask;
fn set_clear_cpu(ptr: *mut bindings::cpumask, set_cpu: u32, clear_cpu: i32) {
// SAFETY: The `ptr` is valid for writing and remains valid for the lifetime of the
// returned reference.
let mask = unsafe { Cpumask::as_mut_ref(ptr) };
mask.set(set_cpu);
mask.clear(clear_cpu);
}
Implementations§
Source§impl Cpumask
impl Cpumask
Sourcepub unsafe fn as_mut_ref<'a>(ptr: *mut cpumask) -> &'a mut Self
pub unsafe fn as_mut_ref<'a>(ptr: *mut cpumask) -> &'a mut Self
Creates a mutable reference to an existing struct cpumask
pointer.
§Safety
The caller must ensure that ptr
is valid for writing and remains valid for the lifetime
of the returned reference.
Sourcepub unsafe fn as_ref<'a>(ptr: *const cpumask) -> &'a Self
pub unsafe fn as_ref<'a>(ptr: *const cpumask) -> &'a Self
Creates a reference to an existing struct cpumask
pointer.
§Safety
The caller must ensure that ptr
is valid for reading and remains valid for the lifetime
of the returned reference.
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.