Note the difference between spin lock and mutex lock :
1 Mutex lock will give up cpu during the waiting period (because
preemption is prohibited when trying to obtain $ )
static inline void spin_lock(spinlock_t *lock)
{
/*
* Spin locks also need to be removed in order to eliminate all
* memory barriers. They are only used by the write side anyway.
*/
#ifndef NO_SYNC_SMP_MB
preempt_disable();
lock_impl_lock(&lock->internal_lock);
#endif
}
2 Compared with mutex locks, spin locks reduce thread scheduling and save costs.
spin_lock 在单cpu 上 禁止抢占 preempt_disable
spin_lock_irq 在单cpu 上 关本地中断 local_irq_disable 再 禁止抢占 preempt_disable