public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-3155] libstdc++: Use std::chrono::steady_clock as atomic_futex reference clock
@ 2020-09-11 13:29 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-09-11 13:29 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:87fce1923fcc8d6ef508500475c149082dc9d338

commit r11-3155-g87fce1923fcc8d6ef508500475c149082dc9d338
Author: Mike Crowe <mac@mcrowe.com>
Date:   Fri Sep 11 14:25:00 2020 +0100

    libstdc++: Use std::chrono::steady_clock as atomic_futex reference clock
    
    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/ChangeLog:
    
            * 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.

Diff:
---
 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 507c5c90610..4375129f34d 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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-11 13:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 13:29 [gcc r11-3155] libstdc++: Use std::chrono::steady_clock as atomic_futex reference clock Jonathan Wakely

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).