From 9e68aa3cc52956ea99bb726c3c29ce0581b9f7e7 Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Wed, 1 Aug 2018 15:39:57 +0000 Subject: [PATCH] Use steady_clock to implement condition_variable::wait_for The C++ standard says that std::condition_variable::wait_for should be implemented to be equivalent to: return wait_until(lock, chrono::steady_clock::now() + rel_time); But the existing implementation uses chrono::system_clock. Now that wait_until has potentially-different behaviour for chrono::steady_clock, let's at least try to wait using the correct clock. 2018-08-01 Mike Crowe * include/std/condition_variable (wait_for): Use steady_clock. From-SVN: r263225 --- libstdc++-v3/ChangeLog | 4 ++++ libstdc++-v3/include/std/condition_variable | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index dc4cc141530..71c01f94997 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,7 @@ +2018-08-01 Mike Crowe + + * include/std/condition_variable (wait_for): Use steady_clock. + 2018-08-01 Mike Crowe * include/std/condition_variable (wait_until): Only report timeout diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index c00afa2b7ae..1f84ea324eb 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -66,6 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class condition_variable { typedef chrono::system_clock __clock_t; + typedef chrono::steady_clock __steady_clock_t; typedef __gthread_cond_t __native_type; #ifdef __GTHREAD_COND_INIT @@ -144,11 +145,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION wait_for(unique_lock& __lock, const chrono::duration<_Rep, _Period>& __rtime) { - using __dur = typename __clock_t::duration; + using __dur = typename __steady_clock_t::duration; auto __reltime = chrono::duration_cast<__dur>(__rtime); if (__reltime < __rtime) ++__reltime; - return wait_until(__lock, __clock_t::now() + __reltime); + return wait_until(__lock, __steady_clock_t::now() + __reltime); } template -- 2.30.2