浏览代码

update atomic.h and add .gitignore

main
chyyuu 11 年前
父节点
当前提交
caeaa7e8c7
共有 2 个文件被更改,包括 27 次插入0 次删除
  1. +3
    -0
      .gitignore
  2. +24
    -0
      code/lab5/libs/atomic.h

+ 3
- 0
.gitignore 查看文件

@ -0,0 +1,3 @@
*~
obj/
bin/

+ 24
- 0
code/lab5/libs/atomic.h 查看文件

@ -53,5 +53,29 @@ test_bit(int nr, volatile void *addr) {
return oldbit != 0;
}
/* *
* test_and_set_bit - Atomically set a bit and return its old value
* @nr: the bit to set
* @addr: the address to count from
* */
static inline bool
test_and_set_bit(int nr, volatile void *addr) {
int oldbit;
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
return oldbit != 0;
}
/* *
* test_and_clear_bit - Atomically clear a bit and return its old value
* @nr: the bit to clear
* @addr: the address to count from
* */
static inline bool
test_and_clear_bit(int nr, volatile void *addr) {
int oldbit;
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
return oldbit != 0;
}
#endif /* !__LIBS_ATOMIC_H__ */

正在加载...
取消
保存