gcc/libstdc++-v3/include/std
Thomas Rodgers b52aef3a8c libstdc++: Refactor/cleanup of C++20 atomic wait implementation
This is a substantial rewrite of the atomic wait/notify (and timed wait
counterparts) implementation.

The previous __platform_wait looped on EINTR however this behavior is
not required by the standard. A new _GLIBCXX_HAVE_PLATFORM_WAIT macro
now controls whether wait/notify are implemented using a platform
specific primitive or with a platform agnostic mutex/condvar. This
patch only supplies a definition for linux futexes. A future update
could add support __ulock_wait/wake on Darwin, for instance.

The members of __waiters were lifted to a new base class. The members
are now arranged such that overall sizeof(__waiter_pool_base) fits in
two cache lines (on platforms with at least 64 byte cache lines). The
definition will also use destructive_interference_size for this if it is
available.

The __waiters type is now specific to untimed waits, and is renamed to
__waiter_pool. Timed waits have a corresponding __timed_waiter_pool
type.  Much of the code has been moved from the previous __atomic_wait()
free function to the __waiter_base template and a __waiter derived type
is provided to implement the un-timed wait operations. A similar change
has been made to the timed wait implementation.

The __atomic_spin code has been extended to take a spin policy which is
invoked after the initial busy wait loop. The default policy is to
return from the spin. The timed wait code adds a timed backoff spinning
policy. The code from <thread> which implements this_thread::sleep_for,
sleep_until has been moved to a new <bits/std_thread_sleep.h> header
which allows the thread sleep code to be consumed without pulling in the
whole of <thread>.

The entry points into the wait/notify code have been restructured to
support either -
   * Testing the current value of the atomic stored at the given address
     and waiting on a notification.
   * Applying a predicate to determine if the wait was satisfied.
The entry points were renamed to make it clear that the wait and wake
operations operate on addresses. The first variant takes the expected
value and a function which returns the current value that should be used
in comparison operations, these operations are named with a _v suffix
(e.g. 'value'). All atomic<_Tp> wait/notify operations use the first
variant. Barriers, latches and semaphores use the predicate variant.

This change also centralizes what it means to compare values for the
purposes of atomic<T>::wait rather than scattering through individual
predicates.

This change also centralizes the repetitive code which adjusts for
different user supplied clocks (this should be moved elsewhere
and all such adjustments should use a common implementation).

This change also removes the hashing of the pointer and uses
the pointer value directly for indexing into the waiters table.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add new <bits/this_thread_sleep.h> header.
	* include/Makefile.in: Regenerate.
	* include/bits/this_thread_sleep.h: New file.
	* include/bits/atomic_base.h: Adjust all calls
	to __atomic_wait/__atomic_notify for new call signatures.
	* include/bits/atomic_timed_wait.h: Extensive rewrite.
	* include/bits/atomic_wait.h: Likewise.
	* include/bits/semaphore_base.h: Adjust all calls
	to __atomic_wait/__atomic_notify for new call signatures.
	* include/std/atomic: Likewise.
	* include/std/barrier: Likewise.
	* include/std/latch: Likewise.
	* include/std/semaphore: Likewise.
	* include/std/thread (this_thread::sleep_for)
	(this_thread::sleep_until): Move to new header.
	* testsuite/29_atomics/atomic/wait_notify/bool.cc: Simplify
	test.
	* testsuite/29_atomics/atomic/wait_notify/generic.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/pointers.cc: Likewise.
	* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise.
	* testsuite/29_atomics/atomic_float/wait_notify.cc: Likewise.
	* testsuite/29_atomics/atomic_integral/wait_notify.cc: Likewise.
	* testsuite/29_atomics/atomic_ref/wait_notify.cc: Likewise.
2021-04-20 15:14:58 +01:00
..
algorithm
any libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
array
atomic libstdc++: Refactor/cleanup of C++20 atomic wait implementation 2021-04-20 15:14:58 +01:00
barrier libstdc++: Refactor/cleanup of C++20 atomic wait implementation 2021-04-20 15:14:58 +01:00
bit libstdc++: Fix <bit> to work freestanding [PR 100060] 2021-04-13 17:54:03 +01:00
bitset libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
charconv libstdc++: Define __cpp_lib_to_chars for C++20 [PR 100146] 2021-04-20 12:50:50 +01:00
chrono libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
codecvt
complex libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
concepts
condition_variable libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
coroutine
deque
execution
filesystem
forward_list
fstream libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
functional
future libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
iomanip
ios
iosfwd
iostream libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
istream libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
iterator
latch libstdc++: Refactor/cleanup of C++20 atomic wait implementation 2021-04-20 15:14:58 +01:00
limits
list
locale
map
memory libstdc++: Fix even more doxygen markup for group close commands 2021-04-09 13:09:23 +01:00
memory_resource
mutex libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
numbers
numeric libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
optional
ostream libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
queue
random
ranges libstdc++: Implement P2259R1 changes [PR95983] 2021-04-20 09:18:50 -04:00
ratio libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
regex
scoped_allocator
semaphore libstdc++: Refactor/cleanup of C++20 atomic wait implementation 2021-04-20 15:14:58 +01:00
set
shared_mutex libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
source_location
span
sstream
stack
stdexcept libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
stop_token
streambuf libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
string
string_view libstdc++: Fix Doxygen warning about ambiguous file name 2021-04-08 14:51:03 +01:00
syncstream
system_error libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
thread libstdc++: Refactor/cleanup of C++20 atomic wait implementation 2021-04-20 15:14:58 +01:00
tuple
type_traits libstdc++: Make std::is_scoped_enum work with incomplete types 2021-04-08 11:56:59 +01:00
typeindex
unordered_map
unordered_set
utility libstdc++: Add nodiscard attribute to cast-like functions 2021-04-06 16:43:25 +01:00
valarray libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
variant libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
vector
version libstdc++: Define __cpp_lib_to_chars for C++20 [PR 100146] 2021-04-20 12:50:50 +01:00