gcc/libstdc++-v3
Mike Crowe 01d412ef36 libstdc++: Support futex waiting on chrono::steady_clock directly
The user-visible effect of this change is for std::future::wait_until to
use CLOCK_MONOTONIC when passed a timeout of std::chrono::steady_clock
type.  This makes it immune to any changes made to the system clock
CLOCK_REALTIME.

Add an overload of __atomic_futex_unsigned::_M_load_and_text_until_impl
that accepts a std::chrono::steady_clock, and correctly passes this
through to __atomic_futex_unsigned_base::_M_futex_wait_until_steady
which uses CLOCK_MONOTONIC for the timeout within the futex system call.
These functions are mostly just copies of the std::chrono::system_clock
versions with small tweaks.

Prior to this commit, a std::chrono::steady timeout would be converted
via std::chrono::system_clock which risks reducing or increasing the
timeout if someone changes CLOCK_REALTIME whilst the wait is happening.
(The commit immediately prior to this one increases the window of
opportunity for that from a short period during the calculation of a
relative timeout, to the entire duration of the wait.)

FUTEX_WAIT_BITSET was added in kernel v2.6.25.  If futex reports ENOSYS
to indicate that this operation is not supported then the code falls
back to using clock_gettime(2) to calculate a relative time to wait for.

I believe that I've added this functionality in a way that it doesn't
break ABI compatibility, but that has made it more verbose and less type
safe.  I believe that it would be better to maintain the timeout as an
instance of the correct clock type all the way down to a single
_M_futex_wait_until function with an overload for each clock.  The
current scheme of separating out the seconds and nanoseconds early risks
accidentally calling the wait function for the wrong clock.
Unfortunately, doing this would break code that compiled against the old
header.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver: Update for addition of
	__atomic_futex_unsigned_base::_M_futex_wait_until_steady.
	* include/bits/atomic_futex.h (__atomic_futex_unsigned_base):
	Add comments to clarify that _M_futex_wait_until and
	_M_load_and_test_until use CLOCK_REALTIME.
	(__atomic_futex_unsigned_base::_M_futex_wait_until_steady)
	(__atomic_futex_unsigned_base::_M_load_and_text_until_steady):
	New member functions that use CLOCK_MONOTONIC.
	(__atomic_futex_unsigned_base::_M_load_and_test_until_impl)
	(__atomic_futex_unsigned_base::_M_load_when_equal_until): Add
	overloads that accept a steady_clock time_point and use the
	new member functions.
	* src/c++11/futex.cc: Include headers required for
	clock_gettime.
	(futex_clock_monotonic_flag): New constant to tell futex to
	use CLOCK_MONOTONIC to match existing futex_clock_realtime_flag.
	(futex_clock_monotonic_unavailable): New global to store the
	result of trying to use CLOCK_MONOTONIC.
	(__atomic_futex_unsigned_base::_M_futex_wait_until_steady): Add
	new variant of _M_futex_wait_until that uses CLOCK_MONOTONIC to
	support waiting using steady_clock.
2020-09-11 14:25:00 +01:00
..
config libstdc++: Support futex waiting on chrono::steady_clock directly 2020-09-11 14:25:00 +01:00
doc libstdc++: Implement P0966 std::string::reserve should not shrink 2020-08-06 19:49:07 +01:00
include libstdc++: Support futex waiting on chrono::steady_clock directly 2020-09-11 14:25:00 +01:00
libsupc++ libstdc++-v3/libsupc++/eh_call.cc: Avoid "set but not used" warning 2020-09-11 13:00:29 +00:00
po libstdc++: Regenerate makefiles 2020-06-23 07:59:40 +01:00
python libstdc++: Fix compatibility support in unique_ptr pretty printer 2020-08-10 18:47:06 +01:00
scripts
src libstdc++: Support futex waiting on chrono::steady_clock directly 2020-09-11 14:25:00 +01:00
testsuite libstdc++: Improve std::async test 2020-09-11 14:24:59 +01:00
acinclude.m4 libstdc++: Deprecate the --enable-cheaders=c_std configuration 2020-08-13 16:33:28 +01:00
aclocal.m4 Add `--with-toolexeclibdir=' configuration option 2020-01-24 11:24:25 +00:00
ChangeLog Daily bump. 2020-09-11 00:16:28 +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 libstdc++: Fix whitespace in ChangeLog-2019 2020-01-09 21:31:35 +00:00
config.h.in libstdc++: Add std::from_chars for floating-point types 2020-07-20 23:49:27 +01:00
configure libstdc++: Deprecate the --enable-cheaders=c_std configuration 2020-08-13 16:33:28 +01:00
configure.ac libstdc++: Add std::from_chars for floating-point types 2020-07-20 23:49:27 +01:00
configure.host aix: Add GCC64 configuration and FAT target libraries. 2020-06-21 14:14:46 -04:00
crossconfig.m4 libstdc++: Add std::from_chars for floating-point types 2020-07-20 23:49:27 +01:00
fragment.am
linkage.m4
Makefile.am build: Use -include instead of conditional include. 2020-06-22 21:31:48 +00:00
Makefile.in build: Use -include instead of conditional include. 2020-06-22 21:31:48 +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.