diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2004-02-27 00:49:50 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2004-02-27 00:49:50 +0000 |
commit | 2c5d0ae842f692b1456cf53d2734457a8f43194f (patch) | |
tree | 886de6d6c6bb866d655ffbb36b4a11fba3620151 /libstdc++-v3/config/cpu | |
parent | 4d5fe28997dc77c3afeb47d400b6e62418705c34 (diff) | |
download | gcc-2c5d0ae842f692b1456cf53d2734457a8f43194f.zip gcc-2c5d0ae842f692b1456cf53d2734457a8f43194f.tar.gz gcc-2c5d0ae842f692b1456cf53d2734457a8f43194f.tar.bz2 |
atomicity.h: New, forward declarations for __atomic_add and __exchange_and_add.
2004-02-25 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/atomicity.h: New, forward declarations for __atomic_add
and __exchange_and_add.
* config/cpu/generic/atomic_word.h: New, typdef for atomic word.
* config/cpu/cris/atomic_word.h: Same.
* config/cpu/sparc/atomic_word.h: Same.
* include/bits/ios_base.h (_Callback_list::_M_remove_reference):
Qualifiy with __gnu_cxx.
(_Callback_list::_M_add_reference): Same.
* include/bits/locale_classes.h (locale::facet::_M_add_reference): Add.
(locale::facet::_M_remove_reference): Same.
(locale::_Impl::_M_add_reference): Add.
(locale::_Impl::_M_remove_reference): Same.
* include/bits/basic_string.h (basic_string::_Rep::_M_refcopy): Same.
(basic_string::_Rep::_M_dispose): Same.
* src/ios.cc (ios_base::xalloc): Same.
* src/ios_init.cc (ios_base::Init::Init): Same.
(ios_base::Init::~Init): Same.
* src/locale.cc (locale::id::_M_id): Same.
* config/cpu/i486/atomicity.h: Use __gnu_cxx namespace. Remove
static, and inline keyworks.
* config/cpu/alpha/atomicity.h: Same.
* config/cpu/cris/atomicity.h: Same.
* config/cpu/generic/atomicity.h: Same.
* config/cpu/hppa/atomicity.h: Same.
* config/cpu/i386/atomicity.h: Same.
* config/cpu/ia64/atomicity.h: Same.
* config/cpu/m68k/atomicity.h: Same.
* config/cpu/mips/atomicity.h: Same.
* config/cpu/powerpc/atomicity.h: Same.
* config/cpu/s390/atomicity.h: Same.
* config/cpu/sparc/atomicity.h: Same.
* src/Makefile.am (host_sources): Add atomicity.cc.
(atomicity.cc): New rule.
* src/Makefile.in: Regenerate.
* include/Makefile.am (host_headers): Remove host atomicity.h.
(host_headers): Add atomic_word.h.
(bits_headers): Add bits atomicity.h.
Change ATOMICITY_INC_SRCDIR to ATOMICITY_SRCDIR.
* include/Makefile.in: Regenerate.
* configure.host (atomic_word_dir): Add.
* configure.ac: Substitute ATOMIC_WORD_SRCDIR. Change
ATOMICITY_INC_SRCDIR to ATOMICITY_SRCDIR.
* configure: Regenerate.
* config/linker-map.gnu: Export __exchange_and_add, and __atomic_add.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Adjust line numbers.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
From-SVN: r78544
Diffstat (limited to 'libstdc++-v3/config/cpu')
-rw-r--r-- | libstdc++-v3/config/cpu/alpha/atomicity.h | 41 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/cris/atomic_word.h | 36 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/cris/atomicity.h | 41 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/generic/atomic_word.h | 35 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/generic/atomicity.h | 51 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/hppa/atomicity.h | 166 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/i386/atomicity.h | 90 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/i486/atomicity.h | 45 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/ia64/atomicity.h | 31 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/m68k/atomicity.h | 186 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/mips/atomicity.h | 96 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/powerpc/atomicity.h | 82 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/s390/atomicity.h | 54 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/sparc/atomic_word.h | 39 | ||||
-rw-r--r-- | libstdc++-v3/config/cpu/sparc/atomicity.h | 188 |
15 files changed, 625 insertions, 556 deletions
diff --git a/libstdc++-v3/config/cpu/alpha/atomicity.h b/libstdc++-v3/config/cpu/alpha/atomicity.h index cb071cd..4eb311b 100644 --- a/libstdc++-v3/config/cpu/alpha/atomicity.h +++ b/libstdc++-v3/config/cpu/alpha/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: Alpha version -*- C++ -*- -// Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 1999, 2000, 2001, 2003, 2004 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 @@ -27,23 +27,22 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> /* @@@ With gas we can play nice .subsection games to get the non-predicted branch pointing forward. But Digital assemblers don't understand those directives. This isn't a terribly important issue, so just ignore it. */ -typedef int _Atomic_word; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - register int __result, __tmp; - - __asm__ __volatile__ ( + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + register int __result, __tmp; + + __asm__ __volatile__ ( "\n$Lxadd_%=:\n\t" "ldl_l %0,%3\n\t" "addl %0,%4,%1\n\t" @@ -53,16 +52,16 @@ __exchange_and_add(volatile _Atomic_word* __mem, int __val) : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem) : "m" (*__mem), "r"(__val)); - return __result; -} + return __result; + } -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) -{ - register _Atomic_word __result; + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + register _Atomic_word __result; - __asm__ __volatile__ ( + __asm__ __volatile__ ( "\n$Ladd_%=:\n\t" "ldl_l %0,%2\n\t" "addl %0,%3,%0\n\t" @@ -71,6 +70,6 @@ __atomic_add(volatile _Atomic_word* __mem, int __val) "mb" : "=&r"(__result), "=m"(*__mem) : "m" (*__mem), "r"(__val)); -} + } +} // namespace __gnu_cxx -#endif /* atomicity.h */ diff --git a/libstdc++-v3/config/cpu/cris/atomic_word.h b/libstdc++-v3/config/cpu/cris/atomic_word.h new file mode 100644 index 0000000..dd2cf6b --- /dev/null +++ b/libstdc++-v3/config/cpu/cris/atomic_word.h @@ -0,0 +1,36 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004 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 _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +// This entity must not cross a page boundary. +typedef int _Atomic_word __attribute__ ((__aligned__ (4))); + +#endif diff --git a/libstdc++-v3/config/cpu/cris/atomicity.h b/libstdc++-v3/config/cpu/cris/atomicity.h index fecb9dc..965e0da 100644 --- a/libstdc++-v3/config/cpu/cris/atomicity.h +++ b/libstdc++-v3/config/cpu/cris/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: CRIS version -*- C++ -*- -// Copyright (C) 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2003, 2004 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 @@ -27,21 +27,19 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> -// This entity must not cross a page boundary. -typedef int _Atomic_word __attribute__ ((__aligned__ (4))); - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(_Atomic_word* __mem, int __val) +namespace __gnu_cxx { - int __tmp; - _Atomic_word __result; + static inline _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(_Atomic_word* __mem, int __val) + { + int __tmp; + _Atomic_word __result; #if (__CRIS_arch_version >= 10) - __asm__ __volatile__ (" clearf \n" + __asm__ __volatile__ (" clearf \n" "0: \n" " move.d %4,%2 \n" " move.d [%3],%0 \n" @@ -53,7 +51,7 @@ __exchange_and_add(_Atomic_word* __mem, int __val) : "=&r" (__result), "=m" (*__mem), "=&r" (__tmp) : "r" (__mem), "g" (__val), "m" (*__mem)); #else - __asm__ __volatile__ (" move $ccr,$r9 \n" + __asm__ __volatile__ (" move $ccr,$r9 \n" " di \n" " move.d %4,%2 \n" " move.d [%3],%0 \n" @@ -65,14 +63,11 @@ __exchange_and_add(_Atomic_word* __mem, int __val) : "r9"); #endif - return __result; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(_Atomic_word* __mem, int __val) -{ - __exchange_and_add(__mem, __val); -} + return __result; + } -#endif /* atomicity.h */ + void + __attribute__ ((__unused__)) + __atomic_add(_Atomic_word* __mem, int __val) + { __exchange_and_add(__mem, __val); } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/generic/atomic_word.h b/libstdc++-v3/config/cpu/generic/atomic_word.h new file mode 100644 index 0000000..b46adc2 --- /dev/null +++ b/libstdc++-v3/config/cpu/generic/atomic_word.h @@ -0,0 +1,35 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004 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 _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +typedef int _Atomic_word; + +#endif diff --git a/libstdc++-v3/config/cpu/generic/atomicity.h b/libstdc++-v3/config/cpu/generic/atomicity.h index 1bee9ea..8481790 100644 --- a/libstdc++-v3/config/cpu/generic/atomicity.h +++ b/libstdc++-v3/config/cpu/generic/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: Generic version -*- C++ -*- -// Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 1999, 2001, 2002, 2003, 2004 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 @@ -27,15 +27,11 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 - +#include <bits/atomicity.h> #include <bits/gthr.h> #define _GLIBCXX_NEED_GENERIC_MUTEX -typedef int _Atomic_word; - namespace __gnu_cxx { extern __gthread_mutex_t _Atomic_add_mutex; @@ -44,34 +40,27 @@ namespace __gnu_cxx 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) -{ + _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); + __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); + _Atomic_word __result; + __gthread_mutex_lock(&__gnu_cxx::_Atomic_add_mutex); + __result = *__mem; + *__mem += __val; - __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); -} + __gthread_mutex_unlock(&__gnu_cxx::_Atomic_add_mutex); + return __result; + } -#endif /* atomicity.h */ + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { __exchange_and_add(__mem, __val); } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/hppa/atomicity.h b/libstdc++-v3/config/cpu/hppa/atomicity.h index b074142..4e0c252 100644 --- a/libstdc++-v3/config/cpu/hppa/atomicity.h +++ b/libstdc++-v3/config/cpu/hppa/atomicity.h @@ -1,90 +1,98 @@ -/* Low-level functions for atomic operations. PA-RISC version. -*- C++ -*- - Copyright 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. +// Low-level functions for atomic operations: PA-RISC version -*- C++ -*- - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. +// Copyright (C) 2002, 2004 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. - The GNU C 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 - Library General Public License for more details. +// 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 Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ +// 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. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +// 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. -typedef int _Atomic_word; +#include <bits/atomicity.h> -template <int __inst> -struct __Atomicity_lock +namespace __gnu_cxx { - static volatile int _S_atomicity_lock; -}; + template<int __inst> + struct __Atomicity_lock + { + static volatile int _S_atomicity_lock; + }; + + template<int __inst> + volatile int + __Atomicity_lock<__inst>::_S_atomicity_lock __attribute__ ((aligned (16))) = 1; -template <int __inst> -volatile int -__Atomicity_lock<__inst>::_S_atomicity_lock __attribute__ ((aligned (16))) = 1; - -/* Because of the lack of weak support when using the hpux - som linker, we explicitly instantiate the atomicity lock - in src/misc-inst.cc when _GLIBCXX_INST_ATOMICITY_LOCK - is defined. */ + /* Because of the lack of weak support when using the hpux + som linker, we explicitly instantiate the atomicity lock + in src/misc-inst.cc when _GLIBCXX_INST_ATOMICITY_LOCK + is defined. */ #ifndef _GLIBCXX_INST_ATOMICITY_LOCK -template volatile int __Atomicity_lock<0>::_S_atomicity_lock; + template volatile int __Atomicity_lock<0>::_S_atomicity_lock; #endif -static inline int -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word result; - int tmp; - volatile int& lock = __Atomicity_lock<0>::_S_atomicity_lock; - - __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" - "cmpib,<>,n 0,%0,.+20\n\t" - "ldw 0(%1),%0\n\t" - "cmpib,= 0,%0,.-4\n\t" - "nop\n\t" - "b,n .-20" - : "=&r" (tmp) - : "r" (&lock)); - - result = *__mem; - *__mem = result + __val; - /* Reset lock with PA 2.0 "ordered" store. */ - __asm__ __volatile__ ("stw,ma %1,0(%0)" - : : "r" (&lock), "r" (tmp) : "memory"); - return result; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(_Atomic_word* __mem, int __val) -{ - int tmp; - volatile int& lock = __Atomicity_lock<0>::_S_atomicity_lock; - - __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" - "cmpib,<>,n 0,%0,.+20\n\t" - "ldw 0(%1),%0\n\t" - "cmpib,= 0,%0,.-4\n\t" - "nop\n\t" - "b,n .-20" - : "=&r" (tmp) - : "r" (&lock)); - - *__mem += __val; - /* Reset lock with PA 2.0 "ordered" store. */ - __asm__ __volatile__ ("stw,ma %1,0(%0)" - : : "r" (&lock), "r" (tmp) : "memory"); -} - -#endif + int + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word result; + int tmp; + volatile int& lock = __Atomicity_lock<0>::_S_atomicity_lock; + + __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" + "cmpib,<>,n 0,%0,.+20\n\t" + "ldw 0(%1),%0\n\t" + "cmpib,= 0,%0,.-4\n\t" + "nop\n\t" + "b,n .-20" + : "=&r" (tmp) + : "r" (&lock)); + + result = *__mem; + *__mem = result + __val; + /* Reset lock with PA 2.0 "ordered" store. */ + __asm__ __volatile__ ("stw,ma %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); + return result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(_Atomic_word* __mem, int __val) + { + int tmp; + volatile int& lock = __Atomicity_lock<0>::_S_atomicity_lock; + + __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" + "cmpib,<>,n 0,%0,.+20\n\t" + "ldw 0(%1),%0\n\t" + "cmpib,= 0,%0,.-4\n\t" + "nop\n\t" + "b,n .-20" + : "=&r" (tmp) + : "r" (&lock)); + + *__mem += __val; + /* Reset lock with PA 2.0 "ordered" store. */ + __asm__ __volatile__ ("stw,ma %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); + } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/i386/atomicity.h b/libstdc++-v3/config/cpu/i386/atomicity.h index 7a949c3..968bd24 100644 --- a/libstdc++-v3/config/cpu/i386/atomicity.h +++ b/libstdc++-v3/config/cpu/i386/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: x86, x >= 3 version -*- C++ -*- -// Copyright (C) 2003 Free Software Foundation, Inc. +// Copyright (C) 2003, 2004 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 @@ -27,50 +27,48 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> -typedef int _Atomic_word; - -template<int __inst> - struct __Atomicity_lock - { - static volatile _Atomic_word _S_atomicity_lock; - }; - -template<int __inst> -volatile _Atomic_word __Atomicity_lock<__inst>::_S_atomicity_lock = 0; - -template volatile _Atomic_word __Atomicity_lock<0>::_S_atomicity_lock; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - register _Atomic_word __result, __tmp = 1; - - /* obtain the atomic exchange/add spin lock */ - do { - __asm__ __volatile__ ("xchg{l} {%0,%1|%1,%0}" - : "=m" (__Atomicity_lock<0>::_S_atomicity_lock), - "+r" (__tmp) - : "m" (__Atomicity_lock<0>::_S_atomicity_lock)); - } while (__tmp); - - __result = *__mem; - *__mem += __val; - - /* release spin lock */ - __Atomicity_lock<0>::_S_atomicity_lock = 0; - - return __result; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) -{ - __exchange_and_add(__mem, __val); -} - -#endif /* atomicity.h */ + template<int __inst> + struct __Atomicity_lock + { + static volatile _Atomic_word _S_atomicity_lock; + }; + + template<int __inst> + volatile _Atomic_word __Atomicity_lock<__inst>::_S_atomicity_lock = 0; + + template volatile _Atomic_word __Atomicity_lock<0>::_S_atomicity_lock; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + register _Atomic_word __result, __tmp = 1; + + // Obtain the atomic exchange/add spin lock. + do + { + __asm__ __volatile__ ("xchg{l} {%0,%1|%1,%0}" + : "=m" (__Atomicity_lock<0>::_S_atomicity_lock), + "+r" (__tmp) + : "m" (__Atomicity_lock<0>::_S_atomicity_lock)); + } + while (__tmp); + + __result = *__mem; + *__mem += __val; + + // Release spin lock. + __Atomicity_lock<0>::_S_atomicity_lock = 0; + + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { __exchange_and_add(__mem, __val); } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/i486/atomicity.h b/libstdc++-v3/config/cpu/i486/atomicity.h index 06ab866..5700bf3 100644 --- a/libstdc++-v3/config/cpu/i486/atomicity.h +++ b/libstdc++-v3/config/cpu/i486/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: x86, x >= 4 version -*- C++ -*- -// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. +// Copyright (C) 1999, 2000, 2001, 2004 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 @@ -27,28 +27,27 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> -typedef int _Atomic_word; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - register _Atomic_word __result; - __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}" - : "=r" (__result), "=m" (*__mem) - : "0" (__val), "m" (*__mem)); - return __result; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}" - : "=m" (*__mem) : "ir" (__val), "m" (*__mem)); -} + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + register _Atomic_word __result; + __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}" + : "=r" (__result), "=m" (*__mem) + : "0" (__val), "m" (*__mem)); + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}" + : "=m" (*__mem) : "ir" (__val), "m" (*__mem)); + } +} // namespace __gnu_cxx -#endif /* atomicity.h */ diff --git a/libstdc++-v3/config/cpu/ia64/atomicity.h b/libstdc++-v3/config/cpu/ia64/atomicity.h index 4408d06..0c3ab33 100644 --- a/libstdc++-v3/config/cpu/ia64/atomicity.h +++ b/libstdc++-v3/config/cpu/ia64/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: IA64 version -*- C++ -*- -// Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2003, 2004 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 @@ -27,25 +27,18 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 - +#include <bits/atomicity.h> #include <ia64intrin.h> -typedef int _Atomic_word; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - return __sync_fetch_and_add(__mem, __val); -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - __sync_fetch_and_add(__mem, __val); + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { return __sync_fetch_and_add(__mem, __val); } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { __sync_fetch_and_add(__mem, __val); } } - -#endif /* atomicity.h */ diff --git a/libstdc++-v3/config/cpu/m68k/atomicity.h b/libstdc++-v3/config/cpu/m68k/atomicity.h index eb801de..b5827320 100644 --- a/libstdc++-v3/config/cpu/m68k/atomicity.h +++ b/libstdc++-v3/config/cpu/m68k/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: m68k version -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004 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 @@ -27,113 +27,107 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 - -typedef int _Atomic_word; +#include <bits/atomicity.h> +namespace __gnu_cxx +{ #if ( defined(__mc68020__) || defined(__mc68030__) \ || defined(__mc68040__) || defined(__mc68060__) ) \ && !defined(__mcpu32__) -// These variants support compare-and-swap. - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - register _Atomic_word __result = *__mem; - register _Atomic_word __temp; - __asm__ __volatile__ ("1: move%.l %0,%1\n\t" - "add%.l %3,%1\n\t" - "cas%.l %0,%1,%2\n\t" - "jne 1b" - : "=d" (__result), "=&d" (__temp), "=m" (*__mem) - : "d" (__val), "0" (__result), "m" (*__mem)); - return __result; -} + // These variants support compare-and-swap. + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + register _Atomic_word __result = *__mem; + register _Atomic_word __temp; + __asm__ __volatile__ ("1: move%.l %0,%1\n\t" + "add%.l %3,%1\n\t" + "cas%.l %0,%1,%2\n\t" + "jne 1b" + : "=d" (__result), "=&d" (__temp), "=m" (*__mem) + : "d" (__val), "0" (__result), "m" (*__mem)); + return __result; + } #elif defined(__rtems__) - /* - * TAS/JBNE is unsafe on systems with strict priority-based scheduling. - * Disable interrupts, which we can do only from supervisor mode. - */ -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word __result; - short __level, __tmpsr; - __asm__ __volatile__ ("move%.w %%sr,%0\n\tor%.l %0,%1\n\tmove%.w %1,%%sr" - : "=d"(__level), "=d"(__tmpsr) : "1"(0x700)); - - __result = *__mem; - *__mem = __result + __val; - - __asm__ __volatile__ ("move%.w %0,%%sr" : : "d"(__level)); - - return __result; -} + // TAS/JBNE is unsafe on systems with strict priority-based scheduling. + // Disable interrupts, which we can do only from supervisor mode. + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __result; + short __level, __tmpsr; + __asm__ __volatile__ ("move%.w %%sr,%0\n\tor%.l %0,%1\n\tmove%.w %1,%%sr" + : "=d"(__level), "=d"(__tmpsr) : "1"(0x700)); + + __result = *__mem; + *__mem = __result + __val; + __asm__ __volatile__ ("move%.w %0,%%sr" : : "d"(__level)); + + return __result; + } #else - -template<int __inst> - struct __Atomicity_lock + + template<int __inst> + struct __Atomicity_lock + { + static volatile unsigned char _S_atomicity_lock; + }; + + template<int __inst> + volatile unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0; + + template volatile unsigned char __Atomicity_lock<0>::_S_atomicity_lock; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) { - static volatile unsigned char _S_atomicity_lock; - }; - -template<int __inst> -volatile unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0; - -template volatile unsigned char __Atomicity_lock<0>::_S_atomicity_lock; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word __result; - -// bset with no immediate addressing (not SMP-safe) + _Atomic_word __result; + + // bset with no immediate addressing (not SMP-safe) #if defined(__mcf5200__) || defined(__mcf5300__) - __asm__ __volatile__("1: bset.b #7,%0@\n\tjbne 1b" - : /* no outputs */ - : "a"(&__Atomicity_lock<0>::_S_atomicity_lock) - : "cc", "memory"); - -// CPU32 and MCF5400 support test-and-set (SMP-safe). + __asm__ __volatile__("1: bset.b #7,%0@\n\tjbne 1b" + : /* no outputs */ + : "a"(&__Atomicity_lock<0>::_S_atomicity_lock) + : "cc", "memory"); + + // CPU32 and MCF5400 support test-and-set (SMP-safe). #elif defined(__mcpu32__) || defined(__mcf5400__) - __asm__ __volatile__("1: tas %0\n\tjbne 1b" - : "+m"(__Atomicity_lock<0>::_S_atomicity_lock) - : /* none */ - : "cc"); - -// Use bset with immediate addressing for 68000/68010 (not SMP-safe) -// NOTE: TAS is available on the 68000, but unsupported by some Amiga -// memory controllers. + __asm__ __volatile__("1: tas %0\n\tjbne 1b" + : "+m"(__Atomicity_lock<0>::_S_atomicity_lock) + : /* none */ + : "cc"); + + // Use bset with immediate addressing for 68000/68010 (not SMP-safe) + // NOTE: TAS is available on the 68000, but unsupported by some Amiga + // memory controllers. #else - __asm__ __volatile__("1: bset.b #7,%0\n\tjbne 1b" - : "+m"(__Atomicity_lock<0>::_S_atomicity_lock) - : /* none */ - : "cc"); + __asm__ __volatile__("1: bset.b #7,%0\n\tjbne 1b" + : "+m"(__Atomicity_lock<0>::_S_atomicity_lock) + : /* none */ + : "cc"); #endif - - __result = *__mem; - *__mem = __result + __val; - - __Atomicity_lock<0>::_S_atomicity_lock = 0; - - return __result; -} - + + __result = *__mem; + *__mem = __result + __val; + + __Atomicity_lock<0>::_S_atomicity_lock = 0; + + return __result; + } + #endif /* TAS / BSET */ -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) -{ - // Careful: using add.l with a memory destination is not - // architecturally guaranteed to be atomic. - (void) __exchange_and_add(__mem, __val); -} - -#endif /* !_GLIBCXX_ATOMICITY_H */ + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + // Careful: using add.l with a memory destination is not + // architecturally guaranteed to be atomic. + __exchange_and_add(__mem, __val); + } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/mips/atomicity.h b/libstdc++-v3/config/cpu/mips/atomicity.h index 3d0c7a1..0871342 100644 --- a/libstdc++-v3/config/cpu/mips/atomicity.h +++ b/libstdc++-v3/config/cpu/mips/atomicity.h @@ -1,6 +1,6 @@ -// Low-level functions for atomic operations. +// Low-level functions for atomic operations: MIPS version -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004 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 @@ -27,57 +27,55 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> -typedef int _Atomic_word; - -static inline int -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - int __result, __tmp; - - __asm__ __volatile__ - ("/* Inline exchange & add */\n\t" - "1:\n\t" - ".set push\n\t" + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __result, __tmp; + + __asm__ __volatile__ + ("/* Inline exchange & add */\n\t" + "1:\n\t" + ".set push\n\t" #if _MIPS_SIM == _ABIO32 - ".set mips2\n\t" + ".set mips2\n\t" #endif - "ll %0,%3\n\t" - "addu %1,%4,%0\n\t" - "sc %1,%2\n\t" - ".set pop\n\t" - "beqz %1,1b\n\t" - "/* End exchange & add */" - : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem) - : "m" (*__mem), "r"(__val)); - - return __result; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) -{ - int __result; - - __asm__ __volatile__ - ("/* Inline atomic add */\n\t" - "1:\n\t" - ".set push\n\t" + "ll %0,%3\n\t" + "addu %1,%4,%0\n\t" + "sc %1,%2\n\t" + ".set pop\n\t" + "beqz %1,1b\n\t" + "/* End exchange & add */" + : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem) + : "m" (*__mem), "r"(__val)); + + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __result; + + __asm__ __volatile__ + ("/* Inline atomic add */\n\t" + "1:\n\t" + ".set push\n\t" #if _MIPS_SIM == _ABIO32 - ".set mips2\n\t" + ".set mips2\n\t" #endif - "ll %0,%2\n\t" - "addu %0,%3,%0\n\t" - "sc %0,%1\n\t" - ".set pop\n\t" - "beqz %0,1b\n\t" - "/* End atomic add */" - : "=&r"(__result), "=m"(*__mem) + "ll %0,%2\n\t" + "addu %0,%3,%0\n\t" + "sc %0,%1\n\t" + ".set pop\n\t" + "beqz %0,1b\n\t" + "/* End atomic add */" + : "=&r"(__result), "=m"(*__mem) : "m" (*__mem), "r"(__val)); -} - -#endif /* atomicity.h */ + } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/powerpc/atomicity.h b/libstdc++-v3/config/cpu/powerpc/atomicity.h index 3b44b7d..7314944 100644 --- a/libstdc++-v3/config/cpu/powerpc/atomicity.h +++ b/libstdc++-v3/config/cpu/powerpc/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: PowerPC version -*- C++ -*- -// Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 1999, 2000, 2001, 2003, 2004 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 @@ -27,8 +27,7 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> #ifdef __PPC405__ #define _STWCX "sync \n\tstwcx. " @@ -36,43 +35,42 @@ #define _STWCX "stwcx. " #endif -typedef int _Atomic_word; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word __tmp, __res; - __asm__ __volatile__ ( - "/* Inline exchange & add */\n" - "0:\t" - "lwarx %0,0,%3 \n\t" - "add%I4 %1,%0,%4 \n\t" - _STWCX " %1,0,%3 \n\t" - "bne- 0b \n\t" - "/* End exchange & add */" - : "=&b"(__res), "=&r"(__tmp), "=m" (*__mem) - : "r" (__mem), "Ir"(__val), "m" (*__mem) - : "cr0"); - return __res; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - _Atomic_word __tmp; - __asm__ __volatile__ ( - "/* Inline atomic add */\n" - "0:\t" - "lwarx %0,0,%2 \n\t" - "add%I3 %0,%0,%3 \n\t" - _STWCX " %0,0,%2 \n\t" - "bne- 0b \n\t" - "/* End atomic add */" - : "=&b"(__tmp), "=m" (*__mem) - : "r" (__mem), "Ir"(__val), "m" (*__mem) - : "cr0"); -} - -#endif /* atomicity.h */ + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __tmp, __res; + __asm__ __volatile__ ( + "/* Inline exchange & add */\n" + "0:\t" + "lwarx %0,0,%3 \n\t" + "add%I4 %1,%0,%4 \n\t" + _STWCX " %1,0,%3 \n\t" + "bne- 0b \n\t" + "/* End exchange & add */" + : "=&b"(__res), "=&r"(__tmp), "=m" (*__mem) + : "r" (__mem), "Ir"(__val), "m" (*__mem) + : "cr0"); + return __res; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __tmp; + __asm__ __volatile__ ( + "/* Inline atomic add */\n" + "0:\t" + "lwarx %0,0,%2 \n\t" + "add%I3 %0,%0,%3 \n\t" + _STWCX " %0,0,%2 \n\t" + "bne- 0b \n\t" + "/* End atomic add */" + : "=&b"(__tmp), "=m" (*__mem) + : "r" (__mem), "Ir"(__val), "m" (*__mem) + : "cr0"); + } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/s390/atomicity.h b/libstdc++-v3/config/cpu/s390/atomicity.h index 8647c76..b979e3a 100644 --- a/libstdc++-v3/config/cpu/s390/atomicity.h +++ b/libstdc++-v3/config/cpu/s390/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: S/390 version -*- C++ -*- -// Copyright (C) 2001, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2003, 2004 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 @@ -27,34 +27,28 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> -typedef int _Atomic_word; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - register _Atomic_word __old_val, __new_val; - - __asm__ __volatile__ (" l %0,0(%3)\n" - "0: lr %1,%0\n" - " ar %1,%4\n" - " cs %0,%1,0(%3)\n" - " jl 0b" - : "=&d" (__old_val), "=&d" (__new_val), "=m" (*__mem) - : "a" (__mem), "d" (__val), "m" (*__mem) : "cc"); - return __old_val; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - __exchange_and_add(__mem, __val); -} - -#endif /* atomicity.h */ - - + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + register _Atomic_word __old_val, __new_val; + + __asm__ __volatile__ (" l %0,0(%3)\n" + "0: lr %1,%0\n" + " ar %1,%4\n" + " cs %0,%1,0(%3)\n" + " jl 0b" + : "=&d" (__old_val), "=&d" (__new_val), "=m" (*__mem) + : "a" (__mem), "d" (__val), "m" (*__mem) : "cc"); + return __old_val; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { __exchange_and_add(__mem, __val); } +} // namespace __gnu_cxx diff --git a/libstdc++-v3/config/cpu/sparc/atomic_word.h b/libstdc++-v3/config/cpu/sparc/atomic_word.h new file mode 100644 index 0000000..941fddd --- /dev/null +++ b/libstdc++-v3/config/cpu/sparc/atomic_word.h @@ -0,0 +1,39 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004 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 _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +#ifdef __arch64__ + typedef long _Atomic_word; +#else + typedef int _Atomic_word; +#endif + +#endif diff --git a/libstdc++-v3/config/cpu/sparc/atomicity.h b/libstdc++-v3/config/cpu/sparc/atomicity.h index 2db079c..6d4b19b 100644 --- a/libstdc++-v3/config/cpu/sparc/atomicity.h +++ b/libstdc++-v3/config/cpu/sparc/atomicity.h @@ -1,6 +1,6 @@ // Low-level functions for atomic operations: Sparc version -*- C++ -*- -// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 1999, 2000, 2001, 2002, 2004 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 @@ -27,105 +27,99 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -#ifndef _GLIBCXX_ATOMICITY_H -#define _GLIBCXX_ATOMICITY_H 1 +#include <bits/atomicity.h> -#ifdef __arch64__ - -typedef long _Atomic_word; - -static inline _Atomic_word -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word __tmp1, __tmp2; - _Atomic_word __val_extended = __val; - - __asm__ __volatile__("1: ldx [%3], %0\n\t" - " add %0, %4, %1\n\t" - " casx [%3], %0, %1\n\t" - " sub %0, %1, %0\n\t" - " brnz,pn %0, 1b\n\t" - " nop" - : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem) - : "r" (__mem), "r" (__val_extended), "m" (*__mem)); - return __tmp2; -} - -static inline void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) +namespace __gnu_cxx { - _Atomic_word __tmp1, __tmp2; - _Atomic_word __val_extended = __val; - - __asm__ __volatile__("1: ldx [%3], %0\n\t" - " add %0, %4, %1\n\t" - " casx [%3], %0, %1\n\t" - " sub %0, %1, %0\n\t" - " brnz,pn %0, 1b\n\t" - " nop" - : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem) - : "r" (__mem), "r" (__val_extended), "m" (*__mem)); -} - +#ifdef __arch64__ + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __tmp1, __tmp2; + _Atomic_word __val_extended = __val; + + __asm__ __volatile__("1: ldx [%3], %0\n\t" + " add %0, %4, %1\n\t" + " casx [%3], %0, %1\n\t" + " sub %0, %1, %0\n\t" + " brnz,pn %0, 1b\n\t" + " nop" + : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem) + : "r" (__mem), "r" (__val_extended), "m" (*__mem)); + return __tmp2; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __tmp1, __tmp2; + _Atomic_word __val_extended = __val; + + __asm__ __volatile__("1: ldx [%3], %0\n\t" + " add %0, %4, %1\n\t" + " casx [%3], %0, %1\n\t" + " sub %0, %1, %0\n\t" + " brnz,pn %0, 1b\n\t" + " nop" + : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem) + : "r" (__mem), "r" (__val_extended), "m" (*__mem)); + } + #else /* __arch32__ */ -typedef int _Atomic_word; - -template<int __inst> - struct __Atomicity_lock + template<int __inst> + struct __Atomicity_lock + { + static unsigned char _S_atomicity_lock; + }; + + template<int __inst> + unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0; + + template unsigned char __Atomicity_lock<0>::_S_atomicity_lock; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) { - static unsigned char _S_atomicity_lock; - }; - -template<int __inst> -unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0; - -template unsigned char __Atomicity_lock<0>::_S_atomicity_lock; - -static int -__attribute__ ((__unused__)) -__exchange_and_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word __result, __tmp; - - __asm__ __volatile__("1: ldstub [%1], %0\n\t" - " cmp %0, 0\n\t" - " bne 1b\n\t" - " nop" - : "=&r" (__tmp) - : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) - : "memory"); - __result = *__mem; - *__mem += __val; - __asm__ __volatile__("stb %%g0, [%0]" - : /* no outputs */ - : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) - : "memory"); - return __result; -} - -static void -__attribute__ ((__unused__)) -__atomic_add(volatile _Atomic_word* __mem, int __val) -{ - _Atomic_word __tmp; - - __asm__ __volatile__("1: ldstub [%1], %0\n\t" - " cmp %0, 0\n\t" - " bne 1b\n\t" - " nop" - : "=&r" (__tmp) - : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) - : "memory"); - *__mem += __val; - __asm__ __volatile__("stb %%g0, [%0]" - : /* no outputs */ - : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) - : "memory"); -} - + _Atomic_word __result, __tmp; + + __asm__ __volatile__("1: ldstub [%1], %0\n\t" + " cmp %0, 0\n\t" + " bne 1b\n\t" + " nop" + : "=&r" (__tmp) + : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + __result = *__mem; + *__mem += __val; + __asm__ __volatile__("stb %%g0, [%0]" + : /* no outputs */ + : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) + { + _Atomic_word __tmp; + + __asm__ __volatile__("1: ldstub [%1], %0\n\t" + " cmp %0, 0\n\t" + " bne 1b\n\t" + " nop" + : "=&r" (__tmp) + : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + *__mem += __val; + __asm__ __volatile__("stb %%g0, [%0]" + : /* no outputs */ + : "r" (&__Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + } #endif /* __arch32__ */ - -#endif /* atomicity.h */ +} // namespace __gnu_cxx |