From 7dcbaaa984509967baf669a2e9888098960bfa9a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 27 Jan 2012 21:26:03 +0100 Subject: [PATCH] re PR libstdc++/51798 (libstdc++ atomicity performance regression due to __sync_fetch_and_add) PR libstdc++/51798 * config/cpu/generic/atomicity_builtins/atomicity.h (__exchange_and_add, __atomic_add): Use __atomic_fetch_add with __ATOMIC_ACQ_REL semantics instead of __sync_fetch_and_add. * include/ext/atomicity.h (__exchange_and_add, __atomic_add): Likewise. From-SVN: r183644 --- libstdc++-v3/ChangeLog | 9 +++++++++ .../config/cpu/generic/atomicity_builtins/atomicity.h | 6 +++--- libstdc++-v3/include/ext/atomicity.h | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0a455335ad7..2dbb665a345 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2012-01-27 Jakub Jelinek + + PR libstdc++/51798 + * config/cpu/generic/atomicity_builtins/atomicity.h + (__exchange_and_add, __atomic_add): Use __atomic_fetch_add + with __ATOMIC_ACQ_REL semantics instead of __sync_fetch_and_add. + * include/ext/atomicity.h (__exchange_and_add, __atomic_add): + Likewise. + 2011-01-27 Rafael Avila de Espindola * libsupc++/typeinfo: Correctly match #pragma GCC visibility diff --git a/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h b/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h index 581c41fda0d..be3c1ffd9ab 100644 --- a/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h +++ b/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h @@ -1,7 +1,7 @@ // Low-level functions for atomic operations: version for CPUs providing // atomic builtins -*- C++ -*- -// Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2006, 2009, 2010, 2012 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 @@ -33,12 +33,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Atomic_word __attribute__ ((__unused__)) __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () - { return __sync_fetch_and_add(__mem, __val); } + { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } void __attribute__ ((__unused__)) __atomic_add(volatile _Atomic_word* __mem, int __val) throw () - { __sync_fetch_and_add(__mem, __val); } + { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/ext/atomicity.h b/libstdc++-v3/include/ext/atomicity.h index c63b1d46361..c603063265f 100644 --- a/libstdc++-v3/include/ext/atomicity.h +++ b/libstdc++-v3/include/ext/atomicity.h @@ -1,6 +1,6 @@ // Support for atomic operations -*- C++ -*- -// Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 +// Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011, 2012 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -45,11 +45,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef _GLIBCXX_ATOMIC_BUILTINS static inline _Atomic_word __exchange_and_add(volatile _Atomic_word* __mem, int __val) - { return __sync_fetch_and_add(__mem, __val); } + { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } static inline void __atomic_add(volatile _Atomic_word* __mem, int __val) - { __sync_fetch_and_add(__mem, __val); } + { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } #else _Atomic_word __attribute__ ((__unused__))