[Top][All Lists]

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

Re: [Qemu-devel] [PATCH] atomic: using memory_order_relaxed for refcnt i

From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH] atomic: using memory_order_relaxed for refcnt inc/dec ops
Date: Fri, 12 Jul 2013 09:24:14 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7

On 07/11/2013 11:32 PM, Liu Ping Fan wrote:
> Refcnt's atomic inc/dec ops are frequent and its idiom need no seq_cst
> order. So to get better performance, it worth to adopt _relaxed
> other than _seq_cst memory model on them.

You'd need to update the documentation then.  As it stands, what you've written
looks like a bug.


This will never be defined.  It's private to the libstdc++ implementation.  See
how we've defined things using __atomic elsewhere in the file, looking at one
of the __ATOMIC defines.

And in either case, it's better form to use positive tests than negative ones.
I.e. #ifdef rather than #ifndef

>  #define atomic_fetch_inc(ptr)  __sync_fetch_and_add(ptr, 1)
>  #define atomic_fetch_dec(ptr)  __sync_fetch_and_add(ptr, -1)

I'd prefer atomic_fetch_inc_relaxed, as that's more self-documenting.

But I'll re-iterate the necessity of documentation in this area.


reply via email to

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