Skip to main content

inject_restart_handler

Function inject_restart_handler 

Source
pub fn inject_restart_handler(handler: fn(ExitCode))
Expand description

Injects a handler that can restart the system.

If no handler is injected, restart calls crate::arch::power::try_restart. Injection replaces that behavior: restart invokes only the injected handler, which may call the architecture-specific operation as part of its own policy.

use ostd::power::{self, ExitCode};

fn init() {
    power::inject_restart_handler(restart_policy);
}

fn restart_policy(code: ExitCode) {
    try_platform_restart();
    ostd::arch::power::try_restart(code);
}

fn try_platform_restart() {
    // Try a platform-specific restart mechanism, if available.
}

The function may be called only once; subsequent calls take no effect.