gcc/libstdc++-v3
Jonathan Wakely 2ac0649d7b libstdc++: Implement C++20 atomic<shared_ptr> and atomic<weak_ptr>
This adds another piece of C++20, the std::atomic specializations for
std::shared_ptr and std::weak_ptr.

The new _Sp_atomic type mimics the structure of shared_ptr<T> and
weak_ptr<T>, holding a T* pointer (the one returned by get() on a
shared_ptr/weak ptr) and a _Sp_counted_base<>* pointer to the
ref-counted control block. For _Sp_atomic the low bit of the control
block pointer is used as a lock bit, to ensure only one thread will
access the object at a time.  The pointer is actually stored as a
uintptr_t to avoid accidental dereferences of the pointer when unlocked
(which would be a race) or when locked (which would dereference the
wrong pointer value due to the low bit being set). To get a raw pointer
to the control block, the lock must be acquired. Converting between a
_Sp_atomic and a shared_ptr or weak_ptr requires manually adjusting the
T* and _Sp_counted_base<>* members of the shared/weak ptr, instead of
going through the public API. This must be done carefully to ensure that
any change in the number of owners is reflected in a ref-count update.

Co-authored-by: Thomas Rodgers <trodgers@redhat.com>
Signed-off-by: Thomas Rodgers <trodgers@redhat.com>

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_atomic.h (__cpp_lib_atomic_shared_ptr):
	New macro.
	(_Sp_atomic): New class template.
	(atomic<shared_ptr<T>>, atomic<weak_ptr<T>>): New partial
	specializations.
	* include/bits/shared_ptr_base.h (__shared_count, __weak_count)
	(__shared_ptr, __weak_ptr): Declare _Sp_atomic as a friend.
	* include/std/version (__cpp_lib_atomic_shared_ptr): New macro.
	* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc: New
	test.
	* testsuite/20_util/weak_ptr/atomic_weak_ptr.cc: New test.
2022-01-17 00:06:28 +00:00
..
config libstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760] 2022-01-10 15:38:47 +01:00
doc libstdc++: Document new std::random_device tokens 2022-01-14 10:14:24 +00:00
include libstdc++: Implement C++20 atomic<shared_ptr> and atomic<weak_ptr> 2022-01-17 00:06:28 +00:00
libsupc++ libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
po libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
python libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
scripts
src libstdc++: Avoid overflow in bounds checks [PR103955] 2022-01-12 09:10:24 -05:00
testsuite libstdc++: Implement C++20 atomic<shared_ptr> and atomic<weak_ptr> 2022-01-17 00:06:28 +00:00
acinclude.m4 libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
aclocal.m4
ChangeLog Daily bump. 2022-01-16 00:16:26 +00:00
ChangeLog-1998
ChangeLog-1999
ChangeLog-2000
ChangeLog-2001
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
ChangeLog-2018
ChangeLog-2019
ChangeLog-2020
ChangeLog-2021
config.h.in
configure libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
configure.ac libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
configure.host
crossconfig.m4
fragment.am
linkage.m4
Makefile.am
Makefile.in libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
README

file: libstdc++-v3/README

New users may wish to point their web browsers to the file
index.html in the 'doc/html' subdirectory.  It contains brief
building instructions and notes on how to configure the library in
interesting ways.