[committed] libstdc++: Fix std::atomic<std::shared_ptr<T>> for AIX [PR104101]

Message ID 20220119010358.3865532-1-jwakely@redhat.com
State Committed
Commit c3861f79859d96777f86a24261fe639538fd2e1c
Headers
Series [committed] libstdc++: Fix std::atomic<std::shared_ptr<T>> for AIX [PR104101] |

Commit Message

Jonathan Wakely Jan. 19, 2022, 1:03 a.m. UTC
  Tested powerpc64le-linux, powerpc-aix, pushed to trunk.


This fixes a testsuite failure on AIX.

The lock function currently just spins, which should be changed to use
back-off, and maybe then _M_val.wait(__current) when supported.

libstdc++-v3/ChangeLog:

	PR libstdc++/104101
	* include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count::lock):
	Only use __thread_relax if __cpp_lib_atomic_wait is defined.
---
 libstdc++-v3/include/bits/shared_ptr_atomic.h | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Hans-Peter Nilsson Jan. 19, 2022, 1:32 a.m. UTC | #1
> From: Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org>
> Date: Wed, 19 Jan 2022 02:03:58 +0100

> Tested powerpc64le-linux, powerpc-aix, pushed to trunk.
> 
> 
> This fixes a testsuite failure

I'm guessing the actual number is in the tens.

> on AIX.

...and by the looks of it, some 60 regressions (as counted
by contrib/regression/btest-gcc.sh) on newlib targets too
for the same reason.

brgds, H-P
  

Patch

diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index 50aa46370ca..35f781dc9a0 100644
--- a/libstdc++-v3/include/bits/shared_ptr_atomic.h
+++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h
@@ -392,7 +392,9 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  auto __current = _M_val.load(memory_order_relaxed);
 	  while (__current & _S_lock_bit)
 	    {
+#if __cpp_lib_atomic_wait
 	      __detail::__thread_relax();
+#endif
 	      __current = _M_val.load(memory_order_relaxed);
 	    }
 
@@ -401,7 +403,9 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 						 __o,
 						 memory_order_relaxed))
 	    {
+#if __cpp_lib_atomic_wait
 	      __detail::__thread_relax();
+#endif
 	      __current = __current & ~_S_lock_bit;
 	    }
 	  return reinterpret_cast<pointer>(__current);