qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool


From: Richard Henderson
Subject: Re: [Qemu-devel] [RFC v1 05/12] atomic: introduce cmpxchg_bool
Date: Fri, 15 Apr 2016 09:22:49 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1

On 04/15/2016 07:23 AM, Alex Bennée wrote:
> +#define atomic_bool_cmpxchg(ptr, old, new)                              \
> +    ({                                                                  \
> +    typeof(*ptr) _old = (old), _new = (new);                            \
> +    bool r;                                                             \
> +    r = __atomic_compare_exchange(ptr, &_old, &_new, false,             \
> +                                  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);  \
> +    r;                                                                  \
> +    })

How are you thinking this will be used?  If a loop like

  do {
    old = atomic_read (ptr);
    new = f(old);
  } while (!atomic_bool_cmpxchg(ptr, old, new));

then it's usually helpful to use a weak compare_exchange (s/false/true/ above).
 This will produce one loop for ll/sc architectures instead of two.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]