This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: Make generic atomicity.h use gthr.h mutexes


On Fri, Nov 08, 2002 at 04:53:14PM -0600, Loren James Rittle wrote:
> This patch has a slight problem in that you can't assume that a gthr.h
> mutex may be statically init'd.  You need to handle systems (esp. in
> the so-called generic code) that only support dynamic init.  Once you
> see how complex this is to get perfectly correct, you will understand
> why I have not volunteered to produce this patch... ;-)

Good point.

Something like this?  (I haven't tried to test it on a dynamic-init system,
since I haven't figure out how to fake one yet.)


Index: config/cpu/generic/atomicity.h
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/config/cpu/generic/atomicity.h,v
retrieving revision 1.4
diff -u -3 -r1.4 atomicity.h
--- config/cpu/generic/atomicity.h	8 Nov 2002 19:24:41 -0000	1.4
+++ config/cpu/generic/atomicity.h	10 Nov 2002 06:18:35 -0000
@@ -37,19 +37,32 @@
 namespace __gnu_cxx
 {
   __gthread_mutex_t _Atomic_add_mutex __attribute__ ((__weak__))
-                                                      = __GTHREAD_MUTEX_INIT;
+#ifdef __GTHREAD_MUTEX_INIT
+                                                      = __GTHREAD_MUTEX_INIT
+#endif
+                                                      ;
+
 }
 
 static inline _Atomic_word
 __attribute__ ((__unused__))
 __exchange_and_add (volatile _Atomic_word* __mem, int __val)
 {
-   _Atomic_word __result;
+#ifndef __GTHREAD_MUTEX_INIT
+  static bool __initialized = false;
+  if (!__initialized)
+  {
+    __GTHREAD_MUTEX_INIT_FUNCTION (_Atomic_add_mutex);
+    __initialized = true;
+  }
+#endif
+
+  _Atomic_word __result;
 


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