On 23/07/2013 00:30, Axel Dörfler wrote: > On 07/23/2013 12:03 AM, Pawel Dziepak wrote: >>>> 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(). > > Ah, now I see where you're coming from. > Since we added those calls ourselves, we're free to define how they > work, at least, and having them both sounds beneficial. > > However, 'xchg' would pretty much violate our coding style guide (and > sounds x86 specific, too), so atomic_exchange() or even > atomic_get_and_set() would be preferable. > I think atomic_set(), and atomic_set64() should be consistent, though, > so whatever you end up naming that exchange function, it should probably > exist in 32 and 64 bit versions. Since atomic_set() returns previous value as per the current API, you might want to use another name for the non-returning version indeed, how about atomic_put() ? François.