Safely giving up a lock before sleeping
Quoted 6 lines
If I implement this by calling
spin_unlock_irqrestore()immediately followed byinterruptible_sleep_on(), then I have a race condition where I could release the lock and immediately have a bottom half handler on another processor grab it, put data in the queue, and wake the wait queue. My original (user-side) process then happily goes to sleep, unaware that new information is available.
DO NOT use sleep_on in new code.
The correct replacement is wait_event() in <linux/wait.h> if the spinlock is a normal (i.e. non-irq) spinlock.
Your spinlock is probably a spin_lock_irq() or spin_lock_bh() lock, then you must build your own wait_event() wrapper.
check <linux/raid/md_k.h> for a wrapper with spin_lock_irq (wait_event_lock_irq)
The mouse driver sample in linux/documentation also explains the correct way to release a lock and schedule.
--
Manfred