易截截图软件、单文件、免安装、纯绿色、仅160KB

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堆栈溢出的经典问题

 Linux堆栈溢出的经典问题
声明:本文章只是我学习的一个记录,有关引用的地方,我都会给出链接的。如果侵犯作者权益,请通知我及时删除。
看了一下,Linux一站式学习的函数调用
,搞的我热血沸腾,立马找你一下这方面的资料看看。终于看到了一个有关Linux堆栈溢出的文章,就拿来试试手了。参考
我的学习linux笔记 ......

关于EeePc的Linux下安装GCC编译器

     最近由于需要,把几年前(有点夸张)的EeePc 1000拿出来,想在它自带的Linux系统下进行编程。谁知道居然没有GCC编译器,所以源码安装肯定是不行的啦。
    后来在终端(ctrl+alt+t)里输入:sudo apt-get install gcc
    发现支持apt-get安装软件,只不过没找到 ......

linux学习第一帖

 买了一本linux命令、编辑器与shell编程,以前学习过一阵子,后来工作实在太忙,没时间看了,今天拿起书一看,以前看的也忘了,所以从今天开始,写博客,每天都看,相信坚持和积累的力量。先给自己打打气吧。
重定向:
  输出重定向:当向linux系统发出命令时,可指示操作系统将输出发送到任何一个指定的设备或 ......

Linux之Makefile (二)

九、模式变量
在GNU的make中,还支持模式变量(Pattern-specific Variable),通过上面的目标变量中,我们知道,变量可以定义在某个目标上。模式变量的好处就是,我们可以给定一种“模式”,可以把变量定义在符合这种模式的所有目标上。
我们知道,make的“模式”一般是至少含有一个“%&rdquo ......

Linux系统日志介绍(syslogd)

  1、介绍:
   大部分的 Linux 系统中都要使用 syslog 工具,它是相当灵活的,能使系统根据不同日志输入项采取不同的活动。syslog 工具由一个守护程序组成。它能接受访问系统的日志信息并且根据 /etc/syslog.conf 配置文件中的指令处理这些信息。程序,守护进程和内核提供了访问系统的日志信息。因此,任何希望生成日 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号