简体   繁体   中英

Why is there no wait_event_…_irqsave() function or macro in the Linux kernel?

In the Linux kernel the function wait_event_lock_irq(wq_head, condition, lock) is provided in include/linux/wait.h that expects lock to be held and unlocks/locks it using spin_lock_irq() and spin_unlock_irq() . Is there a particular reason that something along the lines of wait_event_lock_irqsave() that uses spin_lock_irqsave() / spin_lock_irqrestore() is not provided?

spin_lock_irqsave() and spin_unlock_irqrestore() save and restore the CPU's "interrupts enabled" status flags. If you know you are not running in an interrupt context with interrupts enabled, but need to synchonize with locks taken in interrupt context, you can use spin_lock_irq() and spin_unlock_irq() to disable and re-enable interrupts without preserving ing the "interrupts enabled" status flags.

The wait_event_...() macros should never be called from an interrupt context (because they may sleep), so it is safe for them to assume that they are not called from an interrupt context, so there is no need to preserve the CPU's "interrupts enabled" status flags. The normal (non-IRQ) wait_event_...() macros should also never be called with interrupts disabled (again, because they may sleep), so it is safe for them to assume that interrupts are not disabled. Of course, the wait_event_..._lock_irq() macro are called with interrupts disabled, but they assume that interrupts were enabled before the preceding call to spin_lock_irq() and that interrupts can be safely re-enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM