ARM64: LDXR/STXR vs LDAXR/STLXR

后端 未结 3 1123
轮回少年
轮回少年 2021-01-02 06:16

On iOS, there are two similar functions, OSAtomicAdd32 and OSAtomicAdd32Barrier. I\'m wondering when you would need the Barrier varian

3条回答
  •  暖寄归人
    2021-01-02 06:45

    I would guess that this is simply a way of reproducing existing architecture-independent semantics for this operation.

    With the ldaxr/stlxr pair, the above sequence will assure correct ordering if the AtomicAdd32 is used as a synchronization mechanism (mutex/semaphore) - regardless of whether the resulting higher-level operation is an acquire or release.

    So - this is not about enforcing consistency of the atomic add, but about enforcing ordering between acquiring/releasing a mutex and any operations performed on the resource protected by that mutex.

    It is less efficient than the ldxar/stxr or ldxr/stlxr you would use in a normal native synchronization mechanism, but if you have existing platform-independent code expecting an atomic add with those semantics, this is probably the best way to implement it.

提交回复
热议问题