[haiku-commits] Re: BRANCH pdziepak-github.lock_elision [a18aae1] in src/system/libroot/os/arch: m68k x86 x86_64 arm ppc

  • From: Pawel Dziepak <pdziepak@xxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 23 Jul 2013 00:03:04 +0200

2013/7/22 Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>:
> On 07/22/2013 11:41 PM, Pawel Dziepak wrote:
>>
>> I will replace the atomic_get{,64}() functions with the "_aligned"
>> ones I just introduced. Current atomic_set() apart from setting new
>> value also returns the old one so I guess renaming it to atomic_xchg()
>
>
> Hm, not sure about that; pretty much all atomic setters return the old
> value.
>
>
>> would be a good idea (while atomic_set{,64}_aligned() becomes
>> atomic_set{,64}().).
>
>
> Can't it return the old value as well to join the club? :-)

Unfortunately, no. On x86(_64) to atomically set a value all we need
is a simple mov instruction since all writes and reads to naturally
aligned memory locations are guaranteed to be atomic. If we want to
get the old value we need to use xchg instruction, which is more
expensive than a simple mov. That's why I though about having both
atomic_set() and atomic_xchg().

Paweł

Other related posts: