__xchg 函数的用法
来源:互联网 发布:php usleep函数 编辑:程序博客网 时间:2024/05/18 01:48
CPU X86 32位
文件:arch\x86\include\asm\cmpxchg_32.h
/* * Note: no "lock" prefix even on SMP: xchg always implies lock anyway. * Since this is generally used to protect other memory information, we * use "asm volatile" and "memory" clobbers to prevent gcc from moving * information around. */#define __xchg(x, ptr, size)\({\__typeof(*(ptr)) __x = (x);\switch (size) {\case 1:\{\volatile u8 *__ptr = (volatile u8 *)(ptr);\asm volatile("xchgb %0,%1"\ : "=q" (__x), "+m" (*__ptr)\ : "0" (__x)\ : "memory");\break;\}\case 2:\{\volatile u16 *__ptr = (volatile u16 *)(ptr);\asm volatile("xchgw %0,%1"\ : "=r" (__x), "+m" (*__ptr)\ : "0" (__x)\ : "memory");\break;\}\case 4:\{\volatile u32 *__ptr = (volatile u32 *)(ptr);\asm volatile("xchgl %0,%1"\ : "=r" (__x), "+m" (*__ptr)\ : "0" (__x)\ : "memory");\break;\}\default:\__xchg_wrong_size();\}\__x;\})#define xchg(ptr, v)\__xchg((v), (ptr), sizeof(*ptr))
xchg是宏,不是真正的函数,该宏根据不同的字长调用不用的汇编指令操作。
举例:
int i = 10, j = 20;
xchg(&i, j); 返回值10;
//调用该宏后
i = 20, j = 20
0 1
- __xchg 函数的用法
- U-boot-1.1.6-2008R1到vdsp5(bf561)的移植记录(10):__xchg
- decode 函数的用法
- 格式化函数的用法
- 格式化函数的用法
- sql 函数的用法
- slice函数的用法
- eval函数的用法
- memset函数的用法
- OPENQUERY函数的用法
- parsename函数的用法
- menset函数的用法
- AfxExtractSubString函数的用法
- memset函数的用法
- decode 函数的用法
- Trim 函数的用法
- StrComp()函数的用法
- VA 函数的用法
- Codeforces Round #365 (Div. 2) C. Chris and Road 实数级的二分法、几何
- MySQL常用函数
- Swift类的属性监听器
- 安装Sqlite数据库
- 一位老程序员的心得!
- __xchg 函数的用法
- [LeetCode]374. Guess Number Higher or Lower【&375. Guess Number Higher or Lower II】
- 面试技巧--非技术题
- Win10下配置Apache Http Server与连接CGI
- 最长公共子序列
- 从尾到头打印链表<剑指offer>
- 深度学习笔记(二):简单神经网络,后向传播算法及实现
- libtool: Version mismatch error. 解决方法
- 常用类