Commit 0dc7adb0 by Jonathan Wakely Committed by Jonathan Wakely

Fix ODR violations in code using <ext/atomicity.h>

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
parent 6e158c5f
2019-07-05 Jonathan Wakely <jwakely@redhat.com>
* 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 <jwakely@redhat.com> 2019-07-03 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/91067 PR libstdc++/91067
......
...@@ -44,24 +44,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -44,24 +44,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// __exchange_and_add_dispatch // __exchange_and_add_dispatch
// __atomic_add_dispatch // __atomic_add_dispatch
#ifdef _GLIBCXX_ATOMIC_BUILTINS #ifdef _GLIBCXX_ATOMIC_BUILTINS
static inline _Atomic_word inline _Atomic_word
__attribute__((__always_inline__))
__exchange_and_add(volatile _Atomic_word* __mem, int __val) __exchange_and_add(volatile _Atomic_word* __mem, int __val)
{ return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } { 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_add(volatile _Atomic_word* __mem, int __val)
{ __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); } { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
#else #else
_Atomic_word _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add(volatile _Atomic_word*, int) throw (); __exchange_and_add(volatile _Atomic_word*, int) throw ();
void void
__attribute__ ((__unused__))
__atomic_add(volatile _Atomic_word*, int) throw (); __atomic_add(volatile _Atomic_word*, int) throw ();
#endif #endif
static inline _Atomic_word inline _Atomic_word
__attribute__((__always_inline__))
__exchange_and_add_single(_Atomic_word* __mem, int __val) __exchange_and_add_single(_Atomic_word* __mem, int __val)
{ {
_Atomic_word __result = *__mem; _Atomic_word __result = *__mem;
...@@ -69,36 +70,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -69,36 +70,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __result; return __result;
} }
static inline void inline void
__attribute__((__always_inline__))
__atomic_add_single(_Atomic_word* __mem, int __val) __atomic_add_single(_Atomic_word* __mem, int __val)
{ *__mem += __val; } { *__mem += __val; }
static inline _Atomic_word inline _Atomic_word
__attribute__ ((__unused__)) __attribute__ ((__always_inline__))
__exchange_and_add_dispatch(_Atomic_word* __mem, int __val) __exchange_and_add_dispatch(_Atomic_word* __mem, int __val)
{ {
#ifdef __GTHREADS #ifdef __GTHREADS
if (__gthread_active_p()) if (__gthread_active_p())
return __exchange_and_add(__mem, __val); return __exchange_and_add(__mem, __val);
else
return __exchange_and_add_single(__mem, __val);
#else
return __exchange_and_add_single(__mem, __val);
#endif #endif
return __exchange_and_add_single(__mem, __val);
} }
static inline void inline void
__attribute__ ((__unused__)) __attribute__ ((__always_inline__))
__atomic_add_dispatch(_Atomic_word* __mem, int __val) __atomic_add_dispatch(_Atomic_word* __mem, int __val)
{ {
#ifdef __GTHREADS #ifdef __GTHREADS
if (__gthread_active_p()) if (__gthread_active_p())
__atomic_add(__mem, __val); __atomic_add(__mem, __val);
else
__atomic_add_single(__mem, __val);
#else
__atomic_add_single(__mem, __val);
#endif #endif
__atomic_add_single(__mem, __val);
} }
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment