<div dir="ltr">When reverting something, please say why you're reverting in the revert commit message.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 16, 2019 at 5:18 PM Dan Albert via libcxx-commits <<a href="mailto:libcxx-commits@lists.llvm.org">libcxx-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: danalbert<br>
Date: Mon Sep 16 14:20:32 2019<br>
New Revision: 372034<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=372034&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=372034&view=rev</a><br>
Log:<br>
Revert "Implement std::condition_variable via pthread_cond_clockwait() where available"<br>
<br>
This reverts commit 5e37d7f9ff257ec62d733d3d94b11f03e0fe51ca.<br>
<br>
Modified:<br>
    libcxx/trunk/include/__config<br>
    libcxx/trunk/include/__mutex_base<br>
    libcxx/trunk/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp<br>
<br>
Modified: libcxx/trunk/include/__config<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=372034&r1=372033&r2=372034&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=372034&r1=372033&r2=372034&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/include/__config (original)<br>
+++ libcxx/trunk/include/__config Mon Sep 16 14:20:32 2019<br>
@@ -1087,12 +1087,6 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit<br>
 #  endif // _LIBCPP_HAS_THREAD_API<br>
 #endif // _LIBCPP_HAS_NO_THREADS<br>
<br>
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)<br>
-#  if (defined(__ANDROID__) && __ANDROID_API__ >= 30) || _LIBCPP_GLIBC_PREREQ(2, 30)<br>
-#    define _LIBCPP_HAS_COND_CLOCKWAIT<br>
-#  endif<br>
-#endif<br>
-<br>
 #if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)<br>
 #error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \<br>
        _LIBCPP_HAS_NO_THREADS is not defined.<br>
<br>
Modified: libcxx/trunk/include/__mutex_base<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=372034&r1=372033&r2=372034&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=372034&r1=372033&r2=372034&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/include/__mutex_base (original)<br>
+++ libcxx/trunk/include/__mutex_base Mon Sep 16 14:20:32 2019<br>
@@ -15,7 +15,6 @@<br>
 #include <system_error><br>
 #include <__threading_support><br>
<br>
-#include <time.h><br>
<br>
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)<br>
 #pragma GCC system_header<br>
@@ -338,75 +337,23 @@ public:<br>
 private:<br>
     void __do_timed_wait(unique_lock<mutex>& __lk,<br>
        chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;<br>
-#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)<br>
-    void __do_timed_wait(unique_lock<mutex>& __lk,<br>
-       chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;<br>
-#endif<br>
-    template <class _Clock><br>
-    void __do_timed_wait(unique_lock<mutex>& __lk,<br>
-       chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;<br>
 };<br>
 #endif // !_LIBCPP_HAS_NO_THREADS<br>
<br>
-template <class _Rep, class _Period><br>
+template <class _To, class _Rep, class _Period><br>
 inline _LIBCPP_INLINE_VISIBILITY<br>
 typename enable_if<br>
 <<br>
-    is_floating_point<_Rep>::value,<br>
-    chrono::nanoseconds<br>
+    chrono::__is_duration<_To>::value,<br>
+    _To<br>
 >::type<br>
-__safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)<br>
+__ceil(chrono::duration<_Rep, _Period> __d)<br>
 {<br>
     using namespace chrono;<br>
-    using __ratio = ratio_divide<_Period, nano>;<br>
-    using __ns_rep = nanoseconds::rep;<br>
-    _Rep __result_float = __d.count() * __ratio::num / __ratio::den;<br>
-<br>
-    _Rep __result_max = numeric_limits<__ns_rep>::max();<br>
-    if (__result_float >= __result_max) {<br>
-        return nanoseconds::max();<br>
-    }<br>
-<br>
-    _Rep __result_min = numeric_limits<__ns_rep>::min();<br>
-    if (__result_float <= __result_min) {<br>
-        return nanoseconds::min();<br>
-    }<br>
-<br>
-    return nanoseconds(static_cast<__ns_rep>(__result_float));<br>
-}<br>
-<br>
-template <class _Rep, class _Period><br>
-inline _LIBCPP_INLINE_VISIBILITY<br>
-typename enable_if<br>
-<<br>
-    !is_floating_point<_Rep>::value,<br>
-    chrono::nanoseconds<br>
->::type<br>
-__safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)<br>
-{<br>
-    using namespace chrono;<br>
-    if (__d.count() == 0) {<br>
-        return nanoseconds(0);<br>
-    }<br>
-<br>
-    using __ratio = ratio_divide<_Period, nano>;<br>
-    using __ns_rep = nanoseconds::rep;<br>
-    __ns_rep __result_max = std::numeric_limits<__ns_rep>::max();<br>
-    if (__d.count() > 0 && __d.count() > __result_max / __ratio::num) {<br>
-        return nanoseconds::max();<br>
-    }<br>
-<br>
-    __ns_rep __result_min = std::numeric_limits<__ns_rep>::min();<br>
-    if (__d.count() < 0 && __d.count() < __result_min / __ratio::num) {<br>
-        return nanoseconds::min();<br>
-    }<br>
-<br>
-    __ns_rep __result = __d.count() * __ratio::num / __ratio::den;<br>
-    if (__result == 0) {<br>
-        return nanoseconds(1);<br>
-    }<br>
-<br>
-    return nanoseconds(__result);<br>
+    _To __r = duration_cast<_To>(__d);<br>
+    if (__r < __d)<br>
+        ++__r;<br>
+    return __r;<br>
 }<br>
<br>
 #ifndef _LIBCPP_HAS_NO_THREADS<br>
@@ -424,15 +371,7 @@ condition_variable::wait_until(unique_lo<br>
                                const chrono::time_point<_Clock, _Duration>& __t)<br>
 {<br>
     using namespace chrono;<br>
-    using __clock_tp_ns = time_point<_Clock, nanoseconds>;<br>
-<br>
-    typename _Clock::time_point __now = _Clock::now();<br>
-    if (__t <= __now)<br>
-        return cv_status::timeout;<br>
-<br>
-    __clock_tp_ns __t_ns = __clock_tp_ns(__safe_nanosecond_cast(__t.time_since_epoch()));<br>
-<br>
-    __do_timed_wait(__lk, __t_ns);<br>
+    wait_for(__lk, __t - _Clock::now());<br>
     return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;<br>
 }<br>
<br>
@@ -458,25 +397,15 @@ condition_variable::wait_for(unique_lock<br>
     using namespace chrono;<br>
     if (__d <= __d.zero())<br>
         return cv_status::timeout;<br>
-    using __ns_rep = nanoseconds::rep;<br>
+    typedef time_point<system_clock, duration<long double, nano> > __sys_tpf;<br>
+    typedef time_point<system_clock, nanoseconds> __sys_tpi;<br>
+    __sys_tpf _Max = __sys_tpi::max();<br>
     steady_clock::time_point __c_now = steady_clock::now();<br>
-<br>
-#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)<br>
-    using __clock_tp_ns = time_point<steady_clock, nanoseconds>;<br>
-    __ns_rep __now_count_ns = __safe_nanosecond_cast(__c_now.time_since_epoch()).count();<br>
-#else<br>
-    using __clock_tp_ns = time_point<system_clock, nanoseconds>;<br>
-    __ns_rep __now_count_ns = __safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();<br>
-#endif<br>
-<br>
-    __ns_rep __d_ns_count = __safe_nanosecond_cast(__d).count();<br>
-<br>
-    if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) {<br>
-        __do_timed_wait(__lk, __clock_tp_ns::max());<br>
-    } else {<br>
-        __do_timed_wait(__lk, __clock_tp_ns(nanoseconds(__now_count_ns + __d_ns_count)));<br>
-    }<br>
-<br>
+    system_clock::time_point __s_now = system_clock::now();<br>
+    if (_Max - __d > __s_now)<br>
+        __do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d));<br>
+    else<br>
+        __do_timed_wait(__lk, __sys_tpi::max());<br>
     return steady_clock::now() - __c_now < __d ? cv_status::no_timeout :<br>
                                                  cv_status::timeout;<br>
 }<br>
@@ -492,46 +421,6 @@ condition_variable::wait_for(unique_lock<br>
                       _VSTD::move(__pred));<br>
 }<br>
<br>
-#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)<br>
-inline<br>
-void<br>
-condition_variable::__do_timed_wait(unique_lock<mutex>& __lk,<br>
-     chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT<br>
-{<br>
-    using namespace chrono;<br>
-    if (!__lk.owns_lock())<br>
-        __throw_system_error(EPERM,<br>
-                            "condition_variable::timed wait: mutex not locked");<br>
-    nanoseconds __d = __tp.time_since_epoch();<br>
-    timespec __ts;<br>
-    seconds __s = duration_cast<seconds>(__d);<br>
-    using __ts_sec = decltype(__ts.tv_sec);<br>
-    const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();<br>
-    if (__s.count() < __ts_sec_max)<br>
-    {<br>
-        __ts.tv_sec = static_cast<__ts_sec>(__s.count());<br>
-        __ts.tv_nsec = (__d - __s).count();<br>
-    }<br>
-    else<br>
-    {<br>
-        __ts.tv_sec = __ts_sec_max;<br>
-        __ts.tv_nsec = giga::num - 1;<br>
-    }<br>
-    int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts);<br>
-    if (__ec != 0 && __ec != ETIMEDOUT)<br>
-        __throw_system_error(__ec, "condition_variable timed_wait failed");<br>
-}<br>
-#endif // _LIBCPP_HAS_COND_CLOCKWAIT<br>
-<br>
-template <class _Clock><br>
-inline<br>
-void<br>
-condition_variable::__do_timed_wait(unique_lock<mutex>& __lk,<br>
-     chrono::time_point<_Clock, chrono::nanoseconds> __tp) _NOEXCEPT<br>
-{<br>
-    wait_for(__lk, __tp - _Clock::now());<br>
-}<br>
-<br>
 #endif // !_LIBCPP_HAS_NO_THREADS<br>
<br>
 _LIBCPP_END_NAMESPACE_STD<br>
<br>
Modified: libcxx/trunk/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp?rev=372034&r1=372033&r2=372034&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp?rev=372034&r1=372033&r2=372034&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp (original)<br>
+++ libcxx/trunk/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp Mon Sep 16 14:20:32 2019<br>
@@ -25,12 +25,12 @@<br>
<br>
 #include "test_macros.h"<br>
<br>
-struct TestClock<br>
+struct Clock<br>
 {<br>
     typedef std::chrono::milliseconds duration;<br>
     typedef duration::rep             rep;<br>
     typedef duration::period          period;<br>
-    typedef std::chrono::time_point<TestClock> time_point;<br>
+    typedef std::chrono::time_point<Clock> time_point;<br>
     static const bool is_steady =  true;<br>
<br>
     static time_point now()<br>
@@ -50,40 +50,35 @@ int test2 = 0;<br>
<br>
 int runs = 0;<br>
<br>
-template <typename Clock><br>
 void f()<br>
 {<br>
     std::unique_lock<std::mutex> lk(mut);<br>
     assert(test2 == 0);<br>
     test1 = 1;<br>
     cv.notify_one();<br>
-    typename Clock::time_point t0 = Clock::now();<br>
-    typename Clock::time_point t = t0 + std::chrono::milliseconds(250);<br>
+    Clock::time_point t0 = Clock::now();<br>
+    Clock::time_point t = t0 + Clock::duration(250);<br>
     while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout)<br>
         ;<br>
-    typename Clock::time_point t1 = Clock::now();<br>
+    Clock::time_point t1 = Clock::now();<br>
     if (runs == 0)<br>
     {<br>
-        assert(t1 - t0 < std::chrono::milliseconds(250));<br>
+        assert(t1 - t0 < Clock::duration(250));<br>
         assert(test2 != 0);<br>
     }<br>
     else<br>
     {<br>
-        assert(t1 - t0 - std::chrono::milliseconds(250) < std::chrono::milliseconds(50));<br>
+        assert(t1 - t0 - Clock::duration(250) < Clock::duration(50));<br>
         assert(test2 == 0);<br>
     }<br>
     ++runs;<br>
 }<br>
<br>
-template <typename Clock><br>
-void run_test()<br>
+int main(int, char**)<br>
 {<br>
-    runs = 0;<br>
-    test1 = 0;<br>
-    test2 = 0;<br>
     {<br>
         std::unique_lock<std::mutex>lk(mut);<br>
-        std::thread t(f<Clock>);<br>
+        std::thread t(f);<br>
         assert(test1 == 0);<br>
         while (test1 == 0)<br>
             cv.wait(lk);<br>
@@ -97,7 +92,7 @@ void run_test()<br>
     test2 = 0;<br>
     {<br>
         std::unique_lock<std::mutex>lk(mut);<br>
-        std::thread t(f<Clock>);<br>
+        std::thread t(f);<br>
         assert(test1 == 0);<br>
         while (test1 == 0)<br>
             cv.wait(lk);<br>
@@ -105,12 +100,6 @@ void run_test()<br>
         lk.unlock();<br>
         t.join();<br>
     }<br>
-}<br>
<br>
-int main(int, char**)<br>
-{<br>
-    run_test<TestClock>();<br>
-    run_test<std::chrono::steady_clock>();<br>
-    run_test<std::chrono::system_clock>();<br>
-    return 0;<br>
+  return 0;<br>
 }<br>
<br>
<br>
_______________________________________________<br>
libcxx-commits mailing list<br>
<a href="mailto:libcxx-commits@lists.llvm.org" target="_blank">libcxx-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits</a><br>
</blockquote></div>