OSCompareAndSwap(Mac OS X)是否等于CMPXCHG8B?

最佳答案

您可以在XNU源代码的OSAtomic.s文件中找到原子函数的定义。例如,以下是1486.2.11中的OSAtomicCompareAndSwapPtr for x86_64:

_OSCompareAndSwap64:
_OSCompareAndSwapPtr: #;oldValue, newValue, ptr
    movq         %rdi, %rax
    lock
    cmpxchgq    %rsi, 0(%rdx)   #; CAS (eax is an implicit operand)
    sete        %al             #; did CAS succeed? (TZ=1)
    movzbq      %al, %rax       #; clear out the high bytes
    ret

10-08 08:47