Commit 9e68aa3c by Mike Crowe Committed by Jonathan Wakely

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  <mac@mcrowe.com>

	* include/std/condition_variable (wait_for): Use steady_clock.

From-SVN: r263225
parent 2f593432
2018-08-01 Mike Crowe <mac@mcrowe.com>
* include/std/condition_variable (wait_for): Use steady_clock.
2018-08-01 Mike Crowe <mac@mcrowe.com>
* include/std/condition_variable (wait_until): Only report timeout
if we really have timed out when measured against the
caller-supplied clock.
......
......@@ -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<mutex>& __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<typename _Rep, typename _Period, typename _Predicate>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment