Note: moved this from thread leaf here, because it broke the page formatting.
Can't check any reference now, but I think the whole while loop is roughly:
loop:
mov eax, 1 ; "true"
; edi points to &spinlock
xchg [edi], eax
; eax is AtomicExchange retval
test eax, eax
jnz loop ; while(eax != false)
; we've acquired the lock
X86-64 version is same, except the address is probably in a 64-bit register, like RDI. Although this would also work in 64-bit mode, if the pointer just happens to be in the lower 4 GB.
Can't check any reference now, but I think the whole while loop is roughly:
X86-64 version is same, except the address is probably in a 64-bit register, like RDI. Although this would also work in 64-bit mode, if the pointer just happens to be in the lower 4 GB.