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: back at you


Joel, Here is a *very* lightly tested (i.e. I haven't run it on SMP
hardware, or even against our long-running threaded test case).
Slightly improved version of what you posted (I see a bus error with
your original version, note that "m" constraint actually wants the
base reference not the pointer; however, Joel: you did great for
whipped-up-off-the-cuff ;-).  This is not for approval to commit yet.
We need additional eyes and testing in real context.  I also fixed the
nit I found: i486 was missing from its namesake file!

(Matthias, this is an ABI change but it is perhaps the correct fix to
the problem.  This version as posted will probably silently link
against an older libstdc++.so yet fail at runtime.  I think the
correct fix is to remove __lock and leave an extern for it; add
definition for __lock to a file that only appears in the compiled
libstdc++.[a|so].)

	* configure.target (athlon, i586+): Add i486 to list to use cpu/i486.
	(i386): New case.
	* config/cpu/i386/atomicity.h: New file.

Index: configure.target
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/configure.target,v
retrieving revision 1.57
diff -c -r1.57 configure.target
*** configure.target	15 Apr 2003 06:36:25 -0000	1.57
--- configure.target	25 Apr 2003 21:19:06 -0000
***************
*** 69,75 ****
    alpha*)
      cpu_include_dir="cpu/alpha"
      ;;
!   athlon* | i586 | i686 | i786 | x86_64)
      cpu_include_dir="cpu/i486"
      ;;
    hppa*)
--- 69,78 ----
    alpha*)
      cpu_include_dir="cpu/alpha"
      ;;
!   i386)
!     cpu_include_dir="cpu/i386"
!     ;;
!   athlon* | i486 | i586 | i686 | i786 | x86_64)
      cpu_include_dir="cpu/i486"
      ;;
    hppa*)
Index: config/cpu/i386/atomicity.h
===================================================================
RCS file: config/cpu/i386/atomicity.h
diff -N config/cpu/i386/atomicity.h
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- config/cpu/i386/atomicity.h	25 Apr 2003 21:19:06 -0000
***************
*** 0 ****
--- 1,70 ----
+ // Low-level functions for atomic operations: x86, x >= 3 version  -*- C++ -*-
+ 
+ // Copyright (C) 2003 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
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // As a special exception, you may use this file as part of a free software
+ // library without restriction.  Specifically, if other files instantiate
+ // templates or use macros or inline functions from this file, or you compile
+ // this file and link it with other files to produce an executable, this
+ // file does not by itself cause the resulting executable to be covered by
+ // the GNU General Public License.  This exception does not however
+ // invalidate any other reasons why the executable file might be covered by
+ // the GNU General Public License.
+ 
+ #ifndef _BITS_ATOMICITY_H
+ #define _BITS_ATOMICITY_H	1
+ 
+ typedef int _Atomic_word;
+ 
+ static inline _Atomic_word 
+ __attribute__ ((__unused__))
+ __exchange_and_add (volatile _Atomic_word *__mem, int __val)
+ {
+   register _Atomic_word __result, __tmp = 1;
+   /* According to standard legalese, a race is present here.  However,
+    * g++ initializes function-scope static with value 0 at link time
+    * (last time studied in detail, the same was not true about static
+    * with non-zero value): */
+   static volatile _Atomic_word __lock = 0;
+ 
+   /* obtain the atomic exchange/add lock */
+   do {
+     __asm__ __volatile__("xchgl %0,%1"
+ 			 :"=r" (__tmp)
+ 			 :"m" (__lock), "0" (__lock)
+ 			 :"memory");
+   } while (__tmp);
+ 
+   __result = *__mem;
+   *__mem += __val;
+ 
+   /* release spin lock */
+   __lock = 0; // Why is this OK?
+ 
+   return __result;
+ }
+ 
+ static inline void
+ __attribute__ ((__unused__))
+ __atomic_add (volatile _Atomic_word* __mem, int __val)
+ {
+   __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]