Patchwork libgo patch committed: Add __sync_bool_compare_and_swap_4

login
register
mail settings
Submitter Ian Taylor
Date Feb. 1, 2011, 9:23 p.m.
Message ID <mcrr5brjvpc.fsf@google.com>
Download mbox | patch
Permalink /patch/81379/
State New
Headers show

Comments

Ian Taylor - Feb. 1, 2011, 9:23 p.m.
"Joseph S. Myers" <joseph@codesourcery.com> 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.

Ian

Patch

diff -r 02ed6a2c8d6d libgo/configure.ac
--- a/libgo/configure.ac	Tue Feb 01 12:12:03 2011 -0800
+++ b/libgo/configure.ac	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],
+[libgo_cv_func___sync_bool_compare_and_swap_4],
+[AC_LINK_IFELSE([
+typedef unsigned int uint32  __attribute__ ((mode (SI)));
+uint32 i;
+int main() { return __sync_bool_compare_and_swap (&i, 0, 1); }
+],
+[libgo_cv_func___sync_bool_compare_and_swap_4=yes],
+[libgo_cv_func___sync_bool_compare_and_swap_4=no])])
+if test "$libgo_cv_func___sync_bool_compare_and_swap_4" = "yes"; then
+  AC_DEFINE(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_4, 1,
+    [Define to 1 if the compiler provides the __sync_bool_compare_and_swap function for uint32])
+fi
+
 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 @@ 
 	sem_destroy(&l->sem);
 }
 
-#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#ifndef HAVE_SYNC_BOOL_COMPARE_AND_SWAP_4
 
 // For targets which don't have the required sync support.  Really
 // this should be provided by gcc itself.  FIXME.