Linux原子操作的分析
Linux
原子操作的分析
本文针对Linux提供的原子操作函数
atomic_dec_and_test
做了详细的实例分析,解释了其原子性的本质意义。
并对
volatile
产生的误解做了解释。
1.
atomic_dec_and_test
分析
(
1
)先来看
atomic_dec_and_test
的定义:
11 #ifdef CONFIG_SMP
12 #define LOCK "lock ; "
13 #else
14 #define LOCK ""
15 #endif
137 static __inline__ int atomic_dec_and_test(atomic_t
_
v)
138 {
139 unsigned char c;
140
141 __asm__ __volatile__(
142 LOCK "decl %0; sete %1"
143 :"=m" (v->counter), "=qm" (c)
144 :"m" (v->counter) : "memory");
145 return c !
=
0;
146 }
11–15 this macro is used in the inline assembly part of
some of the functions that follow. It means that
the LOCK macro can always be used. But sometimes (the SMP
case) it invokes the machine
instruction to lock the bus; other times it has no
effect.
142 the SETE instruction sets parameter 1 (the unsigned
char c) to 1 if the zero bit is set in
EFLAGS (i.e. if the result of the subtraction was 0).
143 parameter 0 (the counter field) is write only ("=")
and may be in memory ("m"). Parameter 1
is the unsigned char c declared on line 139. It may be in
a general purpose register, or in
memory ("=qm").
144 parameter 2 is the input parameter i; it is expected
as an immediate integer operand and may be
in a general register ("ir") . Parameter 3 is
the other input, the value in (v-
.
counter)
beforehand. The "memory" operand constraint
tells the compiler that memory will be modified
in an unpredictable manner, so it will not keep memory
values cached in registers across the
group of assembler instructions.
145 if the result of the decrement was 0, then c was set
to 1 on line 142. In that case, c !
=
0 is TRUE.
Otherwise, c was set to 0, and c !
=
0 is FALS
相关文档:
买了一本linux命令、编辑器与shell编程,以前学习过一阵子,后来工作实在太忙,没时间看了,今天拿起书一看,以前看的也忘了,所以从今天开始,写博客,每天都看,相信坚持和积累的力量。先给自己打打气吧。
重定向:
输出重定向:当向linux系统发出命令时,可指示操作系统将输出发送到任何一个指定的设备或 ......
关键词: Linux 系统管理
1、查看某文件 ......
九、模式变量
在GNU的make中,还支持模式变量(Pattern-specific Variable),通过上面的目标变量中,我们知道,变量可以定义在某个目标上。模式变量的好处就是,我们可以给定一种“模式”,可以把变量定义在符合这种模式的所有目标上。
我们知道,make的“模式”一般是至少含有一个“%&rdquo ......
如何查询rpm里的相关的信息 1. 查询已经安装在linux中的软件需要注意的几个参数:
1. 查询已经安装在linux中的软件
需要注意的几个参数:
rpm –qa //查询linux系统上已经安装了那些软件 ,此时的查询最好使用
rpm –qa |more
rpm –qf filename //检查这个文件是在那个软件中安装的
[ro ......
1、介绍:
大部分的 Linux 系统中都要使用 syslog 工具,它是相当灵活的,能使系统根据不同日志输入项采取不同的活动。syslog 工具由一个守护程序组成。它能接受访问系统的日志信息并且根据 /etc/syslog.conf 配置文件中的指令处理这些信息。程序,守护进程和内核提供了访问系统的日志信息。因此,任何希望生成日 ......