What's wrong with this code? Compiler returns ambiguous operand size for dec in unlock function. But, there is qword keyword (size specifier).
class spinlock
{
qword locked;
public:
spinlock() : locked(-1)
{ }
void lock() __attribute__((noinline));
void unlock() __attribute__((noinline));
};
void spinlock::lock()
{
asm(
".intel_syntax noprefix;"
"xor rcx, rcx;"
"loop:;"
"lock xchg qword [%0], rcx;"
"test rcx, rcx;"
"jz loop;"
".att_syntax noprefix;"
:
: "r"(&locked)
: "rcx"
);
}
void spinlock::unlock()
{
asm(
".intel_syntax noprefix;"
"lock dec qword [%0];"
".att_syntax noprefix;"
:
: "r"(&locked)
:
);
}