GNOME Bugzilla – Bug 531902
Use GCC atomic buildins for g_atomic*
Last modified: 2010-05-11 17:46:56 UTC
Hi, it would be nice if glib could use the GCC atomics if building with GCC, at least for architectures were we don't have special assembly code. See http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Atomic-Builtins.html#Atomic-Builtins
PulseAudio has pretty complete atomic operations, from what I can tell, supporting gcc 4.1, libatomic_ops and the Linux kernel as well as inline assembler fallbacks for several architectures, including ARM6+. Perhaps this code should just be adapted to glib?
Created attachment 150832 [details] [review] Proposed patch Use GCC builtin atomic operation if these are available. Add a new file to avoid ifdef macro hell.
Looks very good in general; the one comment I got is that the casts in + return __sync_bool_compare_and_swap ((long *)atomic, + (long)oldval, (long)newval); are probably unnecessary.
Pushed with removal of needless casts. http://git.gnome.org/browse/glib/commit/?id=37716bd00a7911de545ebca3dc7a248503eaf46e
*** Bug 603780 has been marked as a duplicate of this bug. ***
For what it's worth, this introduced bug 617491. Not sure how I didn't see this one going in earlier this year.
In bug 617491 I'm suggesting the patch that was committed be reverted and cleaned up / discussed before going in again.