易截截图软件、单文件、免安装、纯绿色、仅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 Bluetooth编程(三) HCI层编程

1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI)  就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

【转】linux 用户组的权限分配

1、 如何在Linux系统下添加一个帐户:用户名为std02,密码为pwd02?
:#useradd std02
#passwd std02
出现提示输入口令pwd02,再次按提示输入pwd02
也可以:
#useradd -n std02 -p pwd02
2、 新建一个子目录/home/public,让它被所有的用户共享,而且拥有所有权限,但不能被非属主删除?
:#mkdir /home/public
#chm ......

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

     最近由于需要,把几年前(有点夸张)的EeePc 1000拿出来,想在它自带的Linux系统下进行编程。谁知道居然没有GCC编译器,所以源码安装肯定是不行的啦。
    后来在终端(ctrl+alt+t)里输入:sudo apt-get install gcc
    发现支持apt-get安装软件,只不过没找到 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号