• 调用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 )

  • 相关阅读:
    linux execl()函数 关于execl()函数族的用法不在赘述,
    mysql日期格式化
    JavaScript超越了Java,c,python等等成为Stack Overflow上最热门的
    GO语言web框架Gin之完全指南
    计算机专业四年本科的课程表是什么样的?
    文化常识大全201901 普通老百姓交的朋友谓“布衣之交”
    JavaScript超越了Java,c,python等等成为Stack Overflow上最热门的
    linux bash吧,还有啥Bourne Again Shell
    TCP、UDP服务器模型 在网络程序里面,通常都是一
    SpringMVC常见面试题总结(超详细回答)
  • 原文地址:https://www.cnblogs.com/justinzhang/p/2109926.html
Copyright © 2020-2023  润新知