Skip to main content

with_cpu_pin

Function with_cpu_pin 

Source
pub unsafe fn with_cpu_pin<R>(
    operation: impl for<'scope> FnOnce(&CpuPin<'scope>) -> R,
) -> Result<R, CpuLocalError>
Expand description

Runs operation with a validated, non-escaping CPU pin.

The higher-ranked callback prevents retaining the token:

let retained = unsafe { cpu_local::with_cpu_pin(|pin| pin) }.unwrap();

It also cannot be sent to another execution context:

unsafe {
    cpu_local::with_cpu_pin(|pin| {
        std::thread::scope(|scope| scope.spawn(|| drop(pin)));
    })
    .unwrap();
}

§Errors

Returns CpuLocalError::AreaNotInstalled before this CPU has installed its runtime area, or an identity error if the live register and area header disagree.

§Safety

The caller must prevent migration for the complete callback. Offline boot code may call this while the CPU cannot be scheduled; runtime code must hold an appropriate preemption or IRQ guard.