From: Mike Crowe <mac@mcrowe.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH v5 4/8] libstdc++ atomic_futex: Use std::chrono::steady_clock as reference clock
Date: Fri, 29 May 2020 07:17:30 +0100 [thread overview]
Message-ID: <ccf4ef03ccdcb7d50661f309f7fb1bf8f59a7b80.1590732962.git-series.mac@mcrowe.com> (raw)
In-Reply-To: <cover.fd1f19e57a7692d4b098bba72506e3b689dca785.1590732962.git-series.mac@mcrowe.com>
The user-visible effect of this change is that std::future::wait_for now
uses std::chrono::steady_clock to determine the timeout. This makes it
immune to changes made to the system clock. It also means that anyone
using their own clock types with std::future::wait_until will have the
timeout converted to std::chrono::steady_clock rather than
std::chrono::system_clock.
Now that use of both std::chrono::steady_clock and
std::chrono::system_clock are correctly supported for the wait timeout, I
believe that std::chrono::steady_clock is a better choice for the reference
clock that all other clocks are converted to since it is guaranteed to
advance steadily. The previous behaviour of converting to
std::chrono::system_clock risks timeouts changing dramatically when the
system clock is changed.
* libstdc++-v3/include/bits/atomic_futex.h:
(__atomic_futex_unsigned): Change __clock_t typedef to use
steady_clock so that unknown clocks are synced to it rather than
system_clock. Change existing __clock_t overloads of
_M_load_and_text_until_impl and _M_load_when_equal_until to use
system_clock explicitly. Remove comment about DR 887 since these
changes address that problem as best as we currently able.
---
libstdc++-v3/include/bits/atomic_futex.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/include/bits/atomic_futex.h b/libstdc++-v3/include/bits/atomic_futex.h
index 507c5c9..4375129 100644
--- a/libstdc++-v3/include/bits/atomic_futex.h
+++ b/libstdc++-v3/include/bits/atomic_futex.h
@@ -71,7 +71,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template <unsigned _Waiter_bit = 0x80000000>
class __atomic_futex_unsigned : __atomic_futex_unsigned_base
{
- typedef chrono::system_clock __clock_t;
+ typedef chrono::steady_clock __clock_t;
// This must be lock-free and at offset 0.
atomic<unsigned> _M_data;
@@ -169,7 +169,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
unsigned
_M_load_and_test_until_impl(unsigned __assumed, unsigned __operand,
bool __equal, memory_order __mo,
- const chrono::time_point<__clock_t, _Dur>& __atime)
+ const chrono::time_point<std::chrono::system_clock, _Dur>& __atime)
{
auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
@@ -229,7 +229,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_load_when_equal_until(unsigned __val, memory_order __mo,
const chrono::time_point<_Clock, _Duration>& __atime)
{
- // DR 887 - Sync unknown clock to known clock.
const typename _Clock::time_point __c_entry = _Clock::now();
const __clock_t::time_point __s_entry = __clock_t::now();
const auto __delta = __atime - __c_entry;
@@ -241,7 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Duration>
_GLIBCXX_ALWAYS_INLINE bool
_M_load_when_equal_until(unsigned __val, memory_order __mo,
- const chrono::time_point<__clock_t, _Duration>& __atime)
+ const chrono::time_point<std::chrono::system_clock, _Duration>& __atime)
{
unsigned __i = _M_load(__mo);
if ((__i & ~_Waiter_bit) == __val)
--
git-series 0.9.1
next prev parent reply other threads:[~2020-05-29 6:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-29 6:17 [PATCH v5 0/8] std::future::wait_* and std::condition_variable improvements Mike Crowe
2020-05-29 6:17 ` [PATCH v5 1/8] libstdc++: Improve async test Mike Crowe
2020-05-29 6:17 ` [PATCH v5 2/8] libstdc++ futex: Use FUTEX_CLOCK_REALTIME for wait Mike Crowe
2020-11-12 23:07 ` Jonathan Wakely
2020-11-13 21:58 ` Mike Crowe
2020-11-13 22:22 ` Jonathan Wakely
2020-11-14 17:46 ` Mike Crowe
2020-05-29 6:17 ` [PATCH v5 3/8] libstdc++ futex: Support waiting on std::chrono::steady_clock directly Mike Crowe
2020-05-29 6:17 ` Mike Crowe [this message]
2020-05-29 6:17 ` [PATCH v5 5/8] libstdc++ futex: Loop when waiting against arbitrary clock Mike Crowe
2020-09-11 9:47 ` Jonathan Wakely
2020-09-16 11:06 ` Mike Crowe
2020-05-29 6:17 ` [PATCH v5 6/8] libstdc++ atomic_futex: Avoid rounding errors in std::future::wait_* [PR91486] Mike Crowe
2020-09-11 14:40 ` Jonathan Wakely
2020-09-11 17:22 ` Jonathan Wakely
2020-09-11 18:59 ` Jonathan Wakely
2020-09-19 10:37 ` libstdc++: Fix chrono::__detail::ceil to work with C++11 (was Re: [PATCH v5 6/8] libstdc++ atomic_futex: Avoid rounding errors in std::future::wait_* [PR91486]) Mike Crowe
2020-10-05 10:32 ` Jonathan Wakely
2020-09-19 10:50 ` [PATCH v5 6/8] libstdc++ atomic_futex: Avoid rounding errors in std::future::wait_* [PR91486] Mike Crowe
2020-10-05 10:33 ` Jonathan Wakely
2020-05-29 6:17 ` [PATCH v5 7/8] libstdc++ condition_variable: Avoid rounding errors on custom clocks Mike Crowe
2020-05-29 6:17 ` [PATCH v5 8/8] libstdc++: Extra async tests, not for merging Mike Crowe
2020-07-17 8:39 ` [PATCH v5 0/8] std::future::wait_* and std::condition_variable improvements Mike Crowe
2020-07-17 9:34 ` Jonathan Wakely
2020-09-11 13:26 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ccf4ef03ccdcb7d50661f309f7fb1bf8f59a7b80.1590732962.git-series.mac@mcrowe.com \
--to=mac@mcrowe.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).