On 08/11/2011 07:18 PM, Lawrence Crowl wrote:
On 8/11/11, Andrew MacLeod<amacl...@redhat.com>  wrote:
The __sync_mem_fetch_{add,sub,and,xor,or} routines perform the operation
atomically, and return the value that was in memory before the operation
was performed.  As I was working on switching the c++ wrappers to use
these new routines, I discovered we also need the versions which return
the *result* of the operation atomically.
You don't need "after" routines for C++, all the operations can be
implemented on top of "before" routines.

int add_after(atomic<int>&  ai, int i) {
     return add_before(ai, i) + i;
}

Sure.. but if an architecture can more efficiently perform one or the other its better to have the choice. If add_before had to be executed with a compare_and_swap loop, but add_after could be natively performed, you wouldn't want to have to use add_before.

the existing non-memory-model __sync routines provide a 'op_and_fetch' as well as 'fetch_and_op', and separate RTL patterns can be supplied for 'sync_new_op' and 'sync_old_op' for this exact reason. Well, that's my interpretation for their existence anyway :-)

Andrew

Reply via email to