gcc/libstdc++-v3/python
Tomasz Kamiński 59889eaa2b libstdc++: Make atomic<shared_ptr<T>>::wait sensitive to stored pointer only changes [PR118757]
Previously, atomic<shared_ptr<T>>::wait (and the weak_ptr version) was
equivalent to waiting directly on _M_val, which corresponds to the pointer
to the control block (_M_pi). Consequently, wakeups were not triggered if
the stored pointer value was changed to a pointer that uses the same control
block but stores pointer to a different object. Such a pointer can be
constructed using an aliasing constructor.

To address this, wait now uses a generic proxy wait
std::__atomic_wait_address function, which supports waiting until any
predicate is satisfied. The provided predicate now compares both the control
block (_M_pi) and the stored pointer (_M_ptr). Comparing the latter requires
locking the pointer.

Since this function operates on raw pointers, the type of _M_val was changed
from __atomic_base<uintptr_t> to uintptr_t. Invocations of the corresponding
member functions are now replaced with direct use of __atomic builtins.

	PR libstdc++/118757

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_atomic.h (_Atomic_count::_M_wait_unlock):
	Add parameter capturing reference to _M_ptr. Reimplement in terms
	of __atomic_wait_address.
	(_Atomic_count::~_Atomic_count, _Atomic_count::lock)
	(_Atomic_count::unlock, _Atomic_count::_M_swap_unlock): Replace
	invocation of atomic member funcitons with __atomic builtins.
	(_Atomic_count::notify_one, _Atomic_count::notify_all):
	Use __atomic_notify_address.
	(_Sp_atomic::element_type): Define.
	(_Sp_atomic::_M_val): Change type to uintptr_t.
	(_Sp_atomic::wait): Pass _M_ptr to _M_wait_unlock.
	* python/libstdcxx/v6/printers.py:
	* testsuite/20_util/shared_ptr/atomic/pr118757.cc: New test.
	* testsuite/20_util/weak_ptr/pr118757.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-10-14 14:38:30 +02:00
..
libstdcxx libstdc++: Make atomic<shared_ptr<T>>::wait sensitive to stored pointer only changes [PR118757] 2025-10-14 14:38:30 +02:00
Makefile.am Update copyright years. 2025-01-02 11:59:57 +01:00
Makefile.in *: regenerate autotools 2025-10-05 17:14:49 +01:00
hook.in libstdc++: Suppress GDB output from new 'skip' commands [PR118260] 2025-05-12 09:44:43 +01:00