pub struct CpuId(/* private fields */);
Expand description
The CPU ID.
Represents a CPU identifier as a wrapper around an u32
.
§Invariants
The CPU ID lies within the range [0, nr_cpu_ids())
.
§Examples
use kernel::cpu::CpuId;
let cpu = 0;
// SAFETY: 0 is always a valid CPU number.
let id = unsafe { CpuId::from_u32_unchecked(cpu) };
assert_eq!(id.as_u32(), cpu);
assert!(CpuId::from_i32(0).is_some());
assert!(CpuId::from_i32(-1).is_none());
Implementations§
Source§impl CpuId
impl CpuId
Sourcepub unsafe fn from_i32_unchecked(id: i32) -> Self
pub unsafe fn from_i32_unchecked(id: i32) -> Self
Sourcepub fn from_i32(id: i32) -> Option<Self>
pub fn from_i32(id: i32) -> Option<Self>
Creates a new CpuId
from the given id
, checking that it is valid.
Sourcepub unsafe fn from_u32_unchecked(id: u32) -> Self
pub unsafe fn from_u32_unchecked(id: u32) -> Self
Sourcepub fn from_u32(id: u32) -> Option<Self>
pub fn from_u32(id: u32) -> Option<Self>
Creates a new CpuId
from the given id
, checking that it is valid.
Sourcepub fn current() -> Self
pub fn current() -> Self
Returns the ID of the CPU the code is currently running on.
The returned value is considered unstable because it may change unexpectedly due to preemption or CPU migration. It should only be used when the context ensures that the task remains on the same CPU or the users could use a stale (yet valid) CPU ID.
Trait Implementations§
impl Copy for CpuId
impl Eq for CpuId
impl StructuralPartialEq for CpuId
Auto Trait Implementations§
impl Freeze for CpuId
impl RefUnwindSafe for CpuId
impl Send for CpuId
impl Sync for CpuId
impl Unpin for CpuId
impl UnwindSafe for CpuId
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Initializes
slot
. Read more