Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45007
  • 博文数量: 17
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 173
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-27 20:25
文章分类

全部博文(17)

文章存档

2016年(2)

2015年(2)

2014年(13)

我的朋友

分类: LINUX

2014-06-24 09:53:02

 基于2.6.32
/**
 * clear_bit - Clears a bit in memory
 * @nr: Bit to clear
 * @addr: Address to start counting from
 *
 * clear_bit() is atomic and may not be reordered.  However, it does
 * not contain a memory barrier, so if it is used for locking purposes,
 * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
 * in order to ensure changes are visible on other processors.
 */
    static __always_inline void  clear_bit(int nr, volatile unsigned long *addr)
    {
        if (IS_IMMEDIATE(nr)) {
            asm volatile(LOCK_PREFIX "andb %1,%0"
                        : CONST_MASK_ADDR(nr, addr)
                        : "iq" ((u8)~CONST_MASK(nr)));
        } else {
            asm volatile(LOCK_PREFIX "btr %1,%0"
            : BITOP_ADDR(addr)
            : "Ir" (nr));
        }
    }
    提供了barrier的含义是优化屏障,类似asm volatile("" : : : "memory");
    static inline void clear_bit_unlock(unsigned nr, volatile unsigned long *addr)
    {
           barrier();
           clear_bit(nr, addr);
    }
阅读(1722) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~