调用spin_lock_irqsave(&chip->lock,flags); 的下层实现是什么?

调用spin_lock_irqsave(&chip->lock,flags); 的下层实现是什么?

 
#define spin_lock_irqsave(lock, flags) \

do { \

typecheck(unsigned long, flags); \

flags = _spin_lock_irqsave(lock); \

} while (0)
 

 

   1:  /*
   2:  
   3:  * Check at compile time that something is of a particular type.
   4:  
   5:  * Always evaluates to 1 so you may use it easily in comparisons.
   6:  
   7:  */
   8:   
   9:  #define typecheck(type,x) \
  10:   
  11:  ({ type __dummy; \
  12:   
  13:  typeof(x) __dummy2; \
  14:   
  15:  (void)(&__dummy == &__dummy2); \
  16:   
  17:  1; \
  18:   
  19:  })
  20:   

 

#define _spin_lock_irqsave(lock) __spin_lock_irqsave(lock)


static inline unsigned long __spin_lock_irqsave(spinlock_t *lock)

{

unsigned long flags;

local_irq_save(flags);

preempt_disable();

spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);

/*

* On lockdep we dont want the hand-coded irq-enable of

* _raw_spin_lock_flags() code, because lockdep assumes

* that interrupts are not re-enabled during lock-acquire:

*/

#ifdef CONFIG_LOCKDEP

LOCK_CONTENDED(lock, _raw_spin_trylock, _raw_spin_lock);

#else

_raw_spin_lock_flags(lock, &flags);

#endif

return flags;

}
 

为了避免卷入过多的宏定义当中,展开级别暂时停留于此,后面我们将进行最终的展开,展开定义如下所示:

   1:  do { ( { unsigned long __dummy ; 
   2:   
   3:  typeof ( flags ) __dummy2 ; 
   4:   
   5:  ( void ) ( & __dummy == & __dummy2 ) ; 1 ; } ) ; 
   6:   
   7:  flags = __spin_lock_irqsave ( & chip -> lock ) ; 
   8:   
   9:  } while ( 0 )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值