You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ipi.rs
    path of file: ./repos/rCore/kernel/src/arch/x86_64
    
    the code of the file until where you have to start completion: //! Interface for inter-processor interrupt.
//! This module w
    
pub fn invoke_on_allcpu(f: impl Fn() + 'static, wait: bool) {
    // Step 1: initialize
    use super::interrupt::consts::IPIFuncCall;
    let mut apic = unsafe { get_apic() };
    let func = Arc::new(f);
    let cpu_count = super::gdt::Cpu::iter().count();
    let rest_count = Arc::new(AtomicU8::new(cpu_count as u8));
    // Step 2: invoke
    for cpu in super::gdt::Cpu::iter() {
        let func_clone = func.clone();
        let rest_clone = rest_count.clone();
        cpu.notify_event(Box::new(move || {
            func_clone();
            rest_clone.fetch_sub(1, Ordering::Relaxed);
        }));
        apic.send_ipi(cpu.id() as u8, IPIFuncCall as u8);
    }
    if wait {
        // spin if remote invocation do not complete
        while rest_count.load(Ordering::Relaxed) != 0 {
            spin_loop_hint();
        }
    }
}