libgo patch committed: Add __sync_bool_compare_and_swap_4

Message ID
State New
Headers show

Commit Message

Ian Taylor Feb. 1, 2011, 9:23 p.m.
"Joseph S. Myers" <> writes:

> On Tue, 1 Feb 2011, Ian Lance Taylor wrote:
>> The libgo library uses __sync_bool_compare_and_swap_4 (i.e., uses
>> __sync_bool_compare_and_swap on uint32 types).  That function is not
>> available for all gcc targets.  This patch adds the function to the
>> library for those cases.  Ideally this would be handled by libgcc, but
>> that does not currently happen.  This function should be harmless if
>> libgcc does get an implementation.
> On some targets libgcc does have an implementation (ARM, PA, SH Linux - 
> note that for more recent ARM architectures the sync operations are 
> inlined).  The __HAVE_* macros only know about whether the operation can 
> be inlined, not about whether it's available in libgcc.  libstdc++-v3 uses 
> link tests to see if these operations are available (either inlined or in 
> libgcc - or for that matter in libc, which could make sense for kernel 
> helpers accessed through a vDSO).

Thanks for pointing that out.  Fixed like so.  Bootstrapped on
x86_64-unknown-linux-gnu.  Committed to mainline.



diff -r 02ed6a2c8d6d libgo/
--- a/libgo/	Tue Feb 01 12:12:03 2011 -0800
+++ b/libgo/	Tue Feb 01 13:17:19 2011 -0800
@@ -332,6 +332,20 @@ 
 AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
 AC_CHECK_FUNCS(srandom random strsignal)
+AC_CACHE_CHECK([for __sync_bool_compare_and_swap_4],
+typedef unsigned int uint32  __attribute__ ((mode (SI)));
+uint32 i;
+int main() { return __sync_bool_compare_and_swap (&i, 0, 1); }
+if test "$libgo_cv_func___sync_bool_compare_and_swap_4" = "yes"; then
+    [Define to 1 if the compiler provides the __sync_bool_compare_and_swap function for uint32])
 dnl For x86 we want to use the -minline-all-stringops option to avoid
 dnl forcing a stack split when calling memcpy and friends.
 AC_CACHE_CHECK([whether compiler supports -minline-all-stringops],
diff -r 02ed6a2c8d6d libgo/runtime/thread.c
--- a/libgo/runtime/thread.c	Tue Feb 01 12:12:03 2011 -0800
+++ b/libgo/runtime/thread.c	Tue Feb 01 13:17:19 2011 -0800
@@ -77,7 +77,7 @@ 
 // For targets which don't have the required sync support.  Really
 // this should be provided by gcc itself.  FIXME.