从nginx中提取:
static ngx_inline ngx_atomic_uint_t
ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
ngx_atomic_uint_t set)
{
u_char res;
__asm__ volatile (
NGX_SMP_LOCK
" cmpxchgl %3, %1; "
" sete %0; "
: "=a" (res) : "m" (*lock), "a" (old), "r" (set) : "cc", "memory");
return res;
}
我不明白汇编指令的语法组合(它使用的语法与printf
不同),它在做什么呢?
答案 0 :(得分:2)
给定this并忽略操作原子性,函数等效于:
static ngx_inline ngx_atomic_uint_t
ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
ngx_atomic_uint_t set)
{
u_char res;
if (*lock == old){
*lock = set;
res = 1;
} else{
res = *lock
}
return res;
}