This is the mail archive of the 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]

Make generic atomicity.h use gthr.h mutexes

On Tue, Nov 05, 2002 at 12:11:56AM -0500, Phil Edwards wrote:
> On Mon, Nov 04, 2002 at 11:00:49PM -0600, Loren James Rittle wrote:
> > >I was/am expecting that generic/atomicity.h would be fixed to use gthr.h's
> > >mutexes before 3.2.1 is shipped...
> > 
> > As long as the patch to fix i386 isn't moved to release branch before
> > generic/atomicity.h is updated to make correct rather than fast,
> Fixing generic/atomicity.h is something that I should have done some time
> ago.  Mea dorkus culpa, where does the time go.
> I've been making good progress on the other projects that I have to do,
> maybe I'll reward myself with some v3 coding this week.  (Something that
> doesn't use MILSPECs!  Yay!)

Done, patch below.  Richard Earnshaw provided a patch

that was simpler than what I had done, so I took his code and made some

Tested by doing a normal build on an SMP Athlon, then replacing the default
atomicity.h with this one, recompiling and rerunning the testsuite.
No additional regressions.

Also tried to test by building a cross compiler targeting i386-pc-linux-gnu
and running it on an SMP Athlon.  Failed to build libgcc with

  In file included from tconfig.h:23,
                   from /home/pme/src/unified/gcc/libgcc2.c:36:
  /home/pme/src/unified/gcc/config/i386/linux.h:238:20: signal.h: No such file or directory
  /home/pme/src/unified/gcc/config/i386/linux.h:239:26: sys/ucontext.h: No such file or directory
  gmake[2]: *** [libgcc/./_muldi3.o] Error 1

I don't actually have an i386 to test this on.  (My previous computer,
years ago, was an 8086.  I'm not joking.)

This is the only atomicity.h which needs to declare a variable at all.
I believe the best place for such things is in the __gnu_cxx namespace,
rather than at the global level.  Any reasons not to do so?

I don't believe there are any PRs directly associated with

2002-11-07  Phil Edwards  <>
            Richard Earnshaw  <>

	* atomicity.h:  Provide atomic __exchange_and_add and __atomic_add.

Index: atomicity.h
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/config/cpu/generic/atomicity.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 atomicity.h
--- atomicity.h	24 Jun 2002 05:47:28 -0000	1.3
+++ atomicity.h	7 Nov 2002 06:36:39 -0000
@@ -1,6 +1,6 @@
 // Low-level functions for atomic operations: Generic version  -*- C++ -*-
-// Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+// Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -30,22 +30,37 @@
 #define _BITS_ATOMICITY_H	1
+#include <bits/gthr.h>
 typedef int _Atomic_word;
+namespace __gnu_cxx
+  __gthread_mutex_t _Atomic_add_mutex __attribute__ ((__weak__))
+                                                      = __GTHREAD_MUTEX_INIT;
 static inline _Atomic_word
 __attribute__ ((__unused__))
-__exchange_and_add (_Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
-  _Atomic_word __result = *__mem;
-  *__mem += __val;
+   _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 (_Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
-  *__mem += __val;
+  (void) __exchange_and_add (__mem, __val);
 #endif /* atomicity.h */

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