Struct Cpumask

Source
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

Source

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.

Source

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.

Source

pub fn as_raw(&self) -> *mut cpumask

Obtain the raw struct cpumask pointer.

Source

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().

Source

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().

Source

pub fn test(&self, cpu: i32) -> bool

Test cpu in the cpumask.

Equivalent to the kernel’s cpumask_test_cpu API.

Source

pub fn setall(&mut self)

Set all CPUs in the cpumask.

Equivalent to the kernel’s cpumask_setall API.

Source

pub fn empty(&self) -> bool

Checks if cpumask is empty.

Equivalent to the kernel’s cpumask_empty API.

Source

pub fn full(&self) -> bool

Checks if cpumask is full.

Equivalent to the kernel’s cpumask_full API.

Source

pub fn weight(&self) -> u32

Get weight of the cpumask.

Equivalent to the kernel’s cpumask_weight API.

Source

pub fn copy(&self, dstp: &mut Self)

Copy cpumask.

Equivalent to the kernel’s cpumask_copy API.

Auto Trait Implementations§

§

impl !Freeze for Cpumask

§

impl !RefUnwindSafe for Cpumask

§

impl Send for Cpumask

§

impl !Sync for Cpumask

§

impl !Unpin for Cpumask

§

impl UnwindSafe for Cpumask

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.