原子位操作
2016-02-10 22:49
316 查看
include/asm-generic/bitops
针对SMP与非SMP:
置位:
针对SMP与非SMP:
#include <asm/types.h> #include <linux/irqflags.h> #ifdef CONFIG_SMP #include <asm/spinlock.h> #include <asm/cache.h> /* we use L1_CACHE_BYTES */ /* Use an array of spinlocks for our atomic_ts. * Hash function to index into a different SPINLOCK. * Since "a" is usually an address, use one spinlock per cacheline. */ # define ATOMIC_HASH_SIZE 4 # define ATOMIC_HASH(a) (&(__atomic_hash[ (((unsigned long) a)/L1_CACHE_BYTES) & (ATOMIC_HASH_SIZE-1) ])) extern arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned; /* Can't use raw_spin_lock_irq because of #include problems, so * this is the substitute */ #define _atomic_spin_lock_irqsave(l,f) do { \ arch_spinlock_t *s = ATOMIC_HASH(l); \ local_irq_save(f); \ arch_spin_lock(s); \ } while(0) #define _atomic_spin_unlock_irqrestore(l,f) do { \ arch_spinlock_t *s = ATOMIC_HASH(l); \ arch_spin_unlock(s); \ local_irq_restore(f); \ } while(0) #else # define _atomic_spin_lock_irqsave(l,f) do { local_irq_save(f); } while (0) # define _atomic_spin_unlock_irqrestore(l,f) do { local_irq_restore(f); } while (0) #endif
置位:
static inline void set_bit(int nr, volatile unsigned long *addr) { unsigned long mask = BIT_MASK(nr); unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); unsigned long flags; _atomic_spin_lock_irqsave(p, flags); *p |= mask; _atomic_spin_unlock_irqrestore(p, flags); } 等。。。
相关文章推荐
- 245,键盘处理
- 《Python学习手册》(二)
- 有哪些软件堪称「神器」,却不被大众所知?(转)
- QT选择文件对话框实现多种类型文件匹配过滤
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
- js 中的流程控制-循环(for)语句
- CodeForces 266A Stones on the Table
- 华为路由器DCHP服务配置实验(二)
- 华为路由器DCHP服务配置实验(一)
- 线程和指针
- poj2406—KMP next数组的性质求最小周期
- cocos2dx[3.2]——裁剪节点ClippingNode
- poj3461—KMP裸题
- viewutils fragment invalid value for field
- 一位程序员工作10年总结的13个忠告,却让很多人惋惜
- jquery选择器(简易版)
- 实现在edittext中任意插入图片
- Spring之 Auto-Wiring All Beans of Compatible Type
- 【摘】Mysql备份还原数据库之mysqldump实例及参数详细说明
- vim的保存文件和退出命令