@@ -189,8 +189,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
_M_try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
- auto __rtime = __atime - _Clock::now();
- return _M_try_lock_for(__rtime);
+ // The user-supplied clock may not tick at the same rate as
+ // steady_clock, so we must loop in order to guarantee that
+ // the timeout has expired before returning false.
+ auto __now = _Clock::now();
+ while (__atime > __now) {
+ auto __rtime = __atime - __now;
+ if (_M_try_lock_for(__rtime))
+ return true;
+ __now = _Clock::now();
+ }
+ return false;
}
};
@@ -26,6 +26,7 @@
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
+#include <slow_clock.h>
template <typename clock_type>
void test()
@@ -71,4 +72,5 @@ int main()
{
test<std::chrono::system_clock>();
test<std::chrono::steady_clock>();
+ test<slow_clock>();
}
@@ -26,6 +26,7 @@
#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
+#include <slow_clock.h>
template <typename clock_type>
void test()
@@ -71,4 +72,5 @@ int main()
{
test<std::chrono::system_clock>();
test<std::chrono::steady_clock>();
+ test<slow_clock>();
}