From: Jonathan Wakely Date: Fri, 5 Jul 2019 16:10:47 +0000 (+0100) Subject: Fix ODR violations in code using X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0dc7adb03718396db1397be1ba1cb3482af957f7;p=gcc.git Fix ODR violations in code using Because the inline versions of __exchange_and_add and __atomic_add are also marked static, they cannot be used from templates or other inline functions without ODR violations. This change gives them external linkage, but adds the always_inline attribute. * include/ext/atomicity.h [_GLIBCXX_ATOMIC_BUILTINS] (__atomic_add) (__exchange_and_add): Replace static specifier with always_inline attribute. (__exchange_and_add_single, __atomic_add_single): Likewise. (__exchange_and_add_dispatch, __atomic_add_dispatch): Likewise. Also combine !__gthread_active_p() and !__GTHREADS branches. From-SVN: r273144 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0ac7419a2ea..334673c6888 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2019-07-05 Jonathan Wakely + + * include/ext/atomicity.h [_GLIBCXX_ATOMIC_BUILTINS] (__atomic_add) + (__exchange_and_add): Replace static specifier with always_inline + attribute. + (__exchange_and_add_single, __atomic_add_single): Likewise. + (__exchange_and_add_dispatch, __atomic_add_dispatch): Likewise. Also + combine !__gthread_active_p() and !__GTHREADS branches. + 2019-07-03 Jonathan Wakely PR libstdc++/91067 diff --git a/libstdc++-v3/include/ext/atomicity.h b/libstdc++-v3/include/ext/atomicity.h index 0783a58e01a..73225b3de20 100644 --- a/libstdc++-v3/include/ext/atomicity.h +++ b/libstdc++-v3/include/ext/atomicity.h @@ -44,24 +44,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // __exchange_and_add_dispatch // __atomic_add_dispatch #ifdef _GLIBCXX_ATOMIC_BUILTINS - static inline _Atomic_word + inline _Atomic_word + __attribute__((__always_inline__)) __exchange_and_add(volatile _Atomic_word* __mem, int __val) { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } - static inline void + inline void + __attribute__((__always_inline__)) __atomic_add(volatile _Atomic_word* __mem, int __val) { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } #else _Atomic_word - __attribute__ ((__unused__)) __exchange_and_add(volatile _Atomic_word*, int) throw (); void - __attribute__ ((__unused__)) __atomic_add(volatile _Atomic_word*, int) throw (); #endif - static inline _Atomic_word + inline _Atomic_word + __attribute__((__always_inline__)) __exchange_and_add_single(_Atomic_word* __mem, int __val) { _Atomic_word __result = *__mem; @@ -69,36 +70,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __result; } - static inline void + inline void + __attribute__((__always_inline__)) __atomic_add_single(_Atomic_word* __mem, int __val) { *__mem += __val; } - static inline _Atomic_word - __attribute__ ((__unused__)) + inline _Atomic_word + __attribute__ ((__always_inline__)) __exchange_and_add_dispatch(_Atomic_word* __mem, int __val) { #ifdef __GTHREADS if (__gthread_active_p()) return __exchange_and_add(__mem, __val); - else - return __exchange_and_add_single(__mem, __val); -#else - return __exchange_and_add_single(__mem, __val); #endif + return __exchange_and_add_single(__mem, __val); } - static inline void - __attribute__ ((__unused__)) + inline void + __attribute__ ((__always_inline__)) __atomic_add_dispatch(_Atomic_word* __mem, int __val) { #ifdef __GTHREADS if (__gthread_active_p()) __atomic_add(__mem, __val); - else - __atomic_add_single(__mem, __val); -#else - __atomic_add_single(__mem, __val); #endif + __atomic_add_single(__mem, __val); } _GLIBCXX_END_NAMESPACE_VERSION