Search code examples
synchronizationlinux-kerneldevice-driver

SpinLock read_lock_irqsave flags attribute


This is regarding the void spin_lock_irqsave(spinlock_t *lock, unsigned long flags); function call. It is mentioned that previous interrupt state is stored in flags and we can restore them by passing this to spin_unlock_irqrestore function.

But I did not get how flags which is passed by values captures the previous interrupt state when spin_lock_irqsave is called.


Solution

  • spin_lock_irqsave is a macro, not a function. So it can assign to flags even though it's apparently passed by value.

    See:

    http://lxr.linux.no/#linux+v2.6.35.4/include/linux/spinlock.h#L312
    http://lxr.linux.no/#linux+v2.6.35.4/include/linux/spinlock.h#L187