This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] libstdc++/24692


Hi,

given the clean up, the minimal fix for this PR is very simple: when safe, the builtins are available, inline the calls (but keep on providing out of line __exchange_and_add and __atomic_add for binary compatibility). Tested x86/ia64-linux, will wait until monday in case I'm missing pitfalls...

Paolo.

/////////////////
2006-05-29  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/24692
	* include/bits/atomicity.h (__exchange_and_add_multi,
	__atomic_add_multi): New, depending on _GLIBCXX_ATOMIC_BUILTINS,
	inline the atomic builtins.
	(__exchange_and_add_dispatch, __atomic_add_dispatch): Adjust.
	* configure.ac: Define _GLIBCXX_ATOMIC_BUILTINS when the atomic
	builtins are available.
	* configure: Regenerate.
	* config.h.in: Likewise.
Index: include/bits/atomicity.h
===================================================================
--- include/bits/atomicity.h	(revision 114155)
+++ include/bits/atomicity.h	(working copy)
@@ -50,6 +50,34 @@
   __atomic_add(volatile _Atomic_word* __mem, int __val);
 
   static inline _Atomic_word
+  __exchange_and_add_multi(volatile _Atomic_word* __mem, int __val)
+  {
+#ifdef _GLIBCXX_ATOMIC_BUILTINS
+
+    return __sync_fetch_and_add(__mem, __val);
+
+#else
+
+    return __exchange_and_add(__mem, __val);
+
+#endif
+  }
+
+  static inline void
+  __atomic_add_multi(volatile _Atomic_word* __mem, int __val)
+  { 
+#ifdef _GLIBCXX_ATOMIC_BUILTINS
+
+    __sync_fetch_and_add(__mem, __val);
+
+#else
+
+    __atomic_add(__mem, __val);
+
+#endif
+  }
+
+  static inline _Atomic_word
   __exchange_and_add_single(volatile _Atomic_word* __mem, int __val)
   {
     _Atomic_word __result = *__mem;
@@ -68,7 +96,7 @@
 #ifdef __GTHREADS
 
     if (__gthread_active_p())
-      return __exchange_and_add(__mem, __val);
+      return __exchange_and_add_multi(__mem, __val);
     else
       return __exchange_and_add_single(__mem, __val);
 
@@ -86,7 +114,7 @@
 #ifdef __GTHREADS
 
     if (__gthread_active_p())
-      __atomic_add(__mem, __val);
+      __atomic_add_multi(__mem, __val);
     else
       __atomic_add_single(__mem, __val);
 
Index: configure.ac
===================================================================
--- configure.ac	(revision 114155)
+++ configure.ac	(working copy)
@@ -318,6 +318,12 @@
 AC_SUBST(ABI_TWEAKS_SRCDIR)
 AC_SUBST(OS_INC_SRCDIR)
 
+# Atomic builtins can be inlined in bits/atomicity.h.
+if test $atomicity_dir = cpu/generic/atomic_builtins ; then
+  AC_DEFINE([_GLIBCXX_ATOMIC_BUILTINS], 1,
+            [Define if atomic builtins are provided for this platform.])
+fi
+
 # Determine cross-compile flags and AM_CONDITIONALs.
 #AC_SUBST(GLIBCXX_IS_NATIVE)
 #AM_CONDITIONAL(CANADIAN, test $CANADIAN = yes)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]