自旋锁基本用法:
//定义自旋锁
spinlock_t lock;
//初始化自旋锁
spin_lock_init();
//获得自旋锁,无法获得时,在原地打转
spin_lock(lock);
//尝试获得自旋锁,如果能立即获得锁,返回true否则返回false,不在原地打转
spin_trylock(lock);
//释放自旋锁
spin_unlock(lock);
自旋锁其他形式:
//关中断
spin_lock_irq() = spin_lock() + local_irq_disable()
//开中断
spin_unlock_irq() = spin_unlock() + local_irq_enable()
//关中断并保存状态字
spin_lock_irqsave() = spin_lock() + local_irq_save()
//开中断并恢复状态字
spin_unlock_irqrestore() = spin_unlock() + local_irq_restore()
//关底半部
spin_lock_bh() = spin_lock() + local_bh_disable()
//开底半部
spin_unlock_bh() = spin_unlock() + local_bh_enable()
释疑spin_lock_irq spin_lock_irqsave spin_unlock_irqrestore spin_lock_bh
最新推荐文章于 2024-04-05 14:02:12 发布