public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mike Crowe <mac@mcrowe.com>
To: libstdc++@gcc.gnu.org,	gcc-patches@gcc.gnu.org
Cc: Mike Crowe <mac@mcrowe.com>
Subject: [PATCH 4/5] libstdc++ atomic_futex: Use std::chrono::steady_clock as reference clock
Date: Sun, 07 Jan 2018 20:55:00 -0000	[thread overview]
Message-ID: <20180107205532.13138-5-mac@mcrowe.com> (raw)
In-Reply-To: <20180107205532.13138-1-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 | 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 78f39fb4048..7dff848d8ad 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)
-- 
2.11.0


  parent reply	other threads:[~2018-01-07 20:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-07 20:55 [PATCH 0/5] Make std::future::wait_* use std::chrono::steady_clock when required Mike Crowe
2018-01-07 20:55 ` [PATCH 5/5] Extra async tests, not for merging Mike Crowe
2018-01-07 20:55 ` [PATCH 2/5] libstdc++ futex: Use FUTEX_CLOCK_REALTIME for wait Mike Crowe
2018-01-09 13:50   ` Jonathan Wakely
2018-01-09 17:54     ` Mike Crowe
2018-01-12 13:18       ` Torvald Riegel
2018-01-12 14:49         ` Jonathan Wakely
2018-01-12 17:56         ` Joseph Myers
2018-01-07 20:55 ` Mike Crowe [this message]
2018-01-07 20:55 ` [PATCH 3/5] libstdc++ futex: Support waiting on std::chrono::steady_clock directly Mike Crowe
2018-01-07 20:55 ` [PATCH 1/5] Improve libstdc++-v3 async test Mike Crowe
2018-01-09 14:31   ` Jonathan Wakely
2018-01-09 14:43 ` [PATCH 0/5] Make std::future::wait_* use std::chrono::steady_clock when required Jonathan Wakely
2018-01-13 15:30 ` Torvald Riegel
2018-01-14 16:08   ` Mike Crowe
2018-01-14 20:44     ` Mike Crowe
2018-02-14 16:32       ` Mike Crowe

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=20180107205532.13138-5-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).