Reputation: 997
Extracted from 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;
}
I don't understand the syntax the assembly instruction are combined(it's using a different syntax than printf
uses),what is it doing at all?
Upvotes: 2
Views: 196
Reputation: 7879
Given this and ignoring operations atomicity, function is equivalent to:
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;
}
Upvotes: 2