Skip to content

Instantly share code, notes, and snippets.

@itrobotics
Created November 11, 2016 06:38
Show Gist options
  • Save itrobotics/1e00e472ed003ca5886524cf2c36c5b4 to your computer and use it in GitHub Desktop.
Save itrobotics/1e00e472ed003ca5886524cf2c36c5b4 to your computer and use it in GitHub Desktop.
static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock)
{
unsigned long flags;
local_irq_save(flags); // local CPU 中斷關閉, 防ISR搶
preempt_disable(); // preemptive 也禁止, 防止process 也來互搶
spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
....
return flags;
}
/*SMP, 於ISR內使用*/
static inline void __raw_spin_lock(raw_spinlock_t *lock)
{
preempt_disable();
spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); // 要求獲得 lock (lock為一個記憶體變數),要不到就'spin'
LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment