In the Linux Kernel, read/write spin lock is used to synchronize access to the list of the tasks. However whereas read_(un)lock are used for reading, write_(un)lock_irq are used for writing. Why is it needed to disable interrupts while locking for writing?
Share
For a lock that’s ever used in IRQ context, IRQs must be disabled when held. But there are different ways to achieve this.
(I describe spinlocks, read/write locks are the same in this respect)
spin_[un]lockdon’t disable IRQs. Only use them when you know they’re already disabled (e.g. in the interrupt handler).spin_[un]lock_irqdisable/enable IRQs. Only use them when you know they’re NOT disabled before calling the function.sping[un]lock_irq[save|restore]– disable IRQs, then return to the previous state. Can used regardless of IRQ state (at a small cost).I guess the difference you see is due to the different calling contexts, not the read/write difference.