public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use steady_clock to implement condition_variable::wait_for with predicate
@ 2018-09-12 14:35 Mike Crowe
  2018-09-25 14:59 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Crowe @ 2018-09-12 14:35 UTC (permalink / raw)
  To: libstdc++, gcc-patches; +Cc: Mike Crowe, Tom Wood

In r263225 (d2e378182a12d68fe5caeffae681252662a2fe7b), I fixed
condition_variable::wait_for to use std::chrono::steady_clock for the wait.
Unfortunately, I failed to spot that the same fix is required for the
wait_for variant that takes a predicate too.

Reported-by: Tom Wood <tom.wood@redembedded.com>
---
 libstdc++-v3/include/std/condition_variable | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
index 1f84ea324eb..24b96e7c295 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
@@ -158,11 +158,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	       const chrono::duration<_Rep, _Period>& __rtime,
 	       _Predicate __p)
       {
-	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, std::move(__p));
+	return wait_until(__lock, __steady_clock_t::now() + __reltime, std::move(__p));
       }
 
     native_handle_type
-- 
2.11.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use steady_clock to implement condition_variable::wait_for with predicate
  2018-09-12 14:35 [PATCH] Use steady_clock to implement condition_variable::wait_for with predicate Mike Crowe
@ 2018-09-25 14:59 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2018-09-25 14:59 UTC (permalink / raw)
  To: Mike Crowe; +Cc: libstdc++, gcc-patches, Tom Wood

[-- Attachment #1: Type: text/plain, Size: 404 bytes --]

On 12/09/18 15:35 +0100, Mike Crowe wrote:
>In r263225 (d2e378182a12d68fe5caeffae681252662a2fe7b), I fixed
>condition_variable::wait_for to use std::chrono::steady_clock for the wait.
>Unfortunately, I failed to spot that the same fix is required for the
>wait_for variant that takes a predicate too.

Thanks, I'm going to commit this slightly tweaked patch (keeping the
line shorter than 80 columns).



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1469 bytes --]

commit 355442478e2876845564d502d83af4c59f601ec9
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Sep 25 15:10:56 2018 +0100

    Use steady_clock to implement condition_variable::wait_for with predicate
    
    In r263225 (d2e378182a12d68fe5caeffae681252662a2fe7b), I fixed
    condition_variable::wait_for to use std::chrono::steady_clock for the wait.
    Unfortunately, I failed to spot that the same fix is required for the
    wait_for variant that takes a predicate too.
    
    2018-09-25  Mike Crowe  <mac@mcrowe.com>
    
            * include/std/condition_variable (condition_variable::wait_for): Use
            steady clock in overload that uses a predicate.

diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
index 1f84ea324eb..84173012b5b 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
@@ -158,11 +158,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	       const chrono::duration<_Rep, _Period>& __rtime,
 	       _Predicate __p)
       {
-	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, std::move(__p));
+	return wait_until(__lock, __steady_clock_t::now() + __reltime,
+			  std::move(__p));
       }
 
     native_handle_type

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-25 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-12 14:35 [PATCH] Use steady_clock to implement condition_variable::wait_for with predicate Mike Crowe
2018-09-25 14:59 ` 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).