Unreliable Guide To Locking | ||
---|---|---|
Prev | Chapter 2. Two Main Types of Kernel Locks: Spinlocks and Semaphores | Next |
If a bottom half shares
data with user context, you have two problems. Firstly, the current
user context can be interrupted by a bottom half, and secondly, the
critical region could be entered from another CPU. This is where
spin_lock_bh()
(include/linux/spinlock.h) is
used. It disables bottom halves on that CPU, then grabs the lock.
spin_unlock_bh()
does the reverse.
This works perfectly for UP
as well: the spin lock vanishes, and this macro
simply becomes local_bh_disable()
(include/asm/softirq.h), which
protects you from the bottom half being run.