[PATCH] remove target dependency for atomicity.h on ix86

Matthias Klose doko@cs.tu-berlin.de
Wed Apr 23 20:15:00 GMT 2003


The implementation in atomicity.h is selected at configuration time
and is depedendent on gcc's compiler options at runtime. There is no
choice using the i386 and i(x>3)86 variants with an installed
compiler. This patch "merges" the two files.

_GLIBCPP_NEED_GENERIC_MUTEX is defined for both variants.  It is
needed to run a binary compiled for the i386 target with the libstdc++
library built for the i486 variant (i.e. having installed the i486
variant in /usr/lib/i486).

Maybe a better patch installs all atomicity variants and selects them
accordingly at compile time.

	Matthias

2003-04-22  Matthias Klose <doko@debian.org>

	* config/cpu/i486/atomicity.h, config/cpu/generic/atomicity.h:
	Select implementation according to predefined __<cpu> macros.


--- libstdc++-v3/config/cpu/i486/atomicity.h~	2002-06-24 07:47:41.000000000 +0200
+++ libstdc++-v3/config/cpu/i486/atomicity.h	2003-04-23 09:30:07.000000000 +0200
@@ -30,16 +30,24 @@
 #ifndef _BITS_ATOMICITY_H
 #define _BITS_ATOMICITY_H	1
 
+#include <bits/gthr.h>
+
+// need to define this in any case
+#define _GLIBCPP_NEED_GENERIC_MUTEX
+
 typedef int _Atomic_word;
 
-static inline _Atomic_word 
+#if defined(__i486) || defined(__i586) || defined(__i686) || defined(__k6) || defined(__athlon) || defined(__pentium4) || defined(__x86_64)
+// the "i486" and above part
+
+static inline _Atomic_word
 __attribute__ ((__unused__))
 __exchange_and_add (volatile _Atomic_word *__mem, int __val)
 {
   register _Atomic_word __result;
   __asm__ __volatile__ ("lock; xaddl %0,%2"
-			: "=r" (__result) 
-                        : "0" (__val), "m" (*__mem) 
+			: "=r" (__result)
+                        : "0" (__val), "m" (*__mem)
                         : "memory");
   return __result;
 }
@@ -52,6 +60,46 @@
 			: : "ir" (__val), "m" (*__mem) : "memory");
 }
 
-#endif /* atomicity.h */
+#else
+// the "generic" (i386) part
+
+namespace __gnu_cxx
+{
+  extern __gthread_mutex_t _Atomic_add_mutex;
+
+#ifndef __GTHREAD_MUTEX_INIT
+  extern __gthread_once_t _Atomic_add_mutex_once;
+  extern void __gthread_atomic_add_mutex_once();
+#endif
+}
+
+static inline _Atomic_word
+__attribute__ ((__unused__))
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
+{
+#ifndef __GTHREAD_MUTEX_INIT
+  __gthread_once (&__gnu_cxx::_Atomic_add_mutex_once,
+                  __gnu_cxx::__gthread_atomic_add_mutex_once);
+#endif
+
+  _Atomic_word __result;
 
+  __gthread_mutex_lock (&__gnu_cxx::_Atomic_add_mutex);
 
+  __result = *__mem;
+  *__mem += __val;
+
+  __gthread_mutex_unlock (&__gnu_cxx::_Atomic_add_mutex);
+  return __result;
+}
+
+
+static inline void
+__attribute__ ((__unused__))
+__atomic_add (volatile _Atomic_word* __mem, int __val)
+{
+  (void) __exchange_and_add (__mem, __val);
+}
+
+#endif
+#endif /* atomicity.h */
--- libstdc++-v3/config/cpu/generic/atomicity.h~	2003-02-22 06:08:04.000000000 +0100
+++ libstdc++-v3/config/cpu/generic/atomicity.h	2003-04-23 09:24:46.000000000 +0200
@@ -32,10 +32,37 @@
 
 #include <bits/gthr.h>
 
+// need to define this in any case
 #define _GLIBCPP_NEED_GENERIC_MUTEX
 
 typedef int _Atomic_word;
 
+#if defined(__i486) || defined(__i586) || defined(__i686) || defined(__k6) || defined(__athlon) || defined(__pentium4) || defined(__x86_64)
+// the "i486" and above part
+
+static inline _Atomic_word
+__attribute__ ((__unused__))
+__exchange_and_add (volatile _Atomic_word *__mem, int __val)
+{
+  register _Atomic_word __result;
+  __asm__ __volatile__ ("lock; xaddl %0,%2"
+			: "=r" (__result)
+                        : "0" (__val), "m" (*__mem)
+                        : "memory");
+  return __result;
+}
+
+static inline void
+__attribute__ ((__unused__))
+__atomic_add (volatile _Atomic_word* __mem, int __val)
+{
+  __asm__ __volatile__ ("lock; addl %0,%1"
+			: : "ir" (__val), "m" (*__mem) : "memory");
+}
+
+#else
+// the "generic" (i386) part
+
 namespace __gnu_cxx
 {
   extern __gthread_mutex_t _Atomic_add_mutex;
@@ -74,4 +101,5 @@
   (void) __exchange_and_add (__mem, __val);
 }
 
+#endif
 #endif /* atomicity.h */



More information about the Libstdc++ mailing list