diff options
| author | Dan Albert <danalbert@google.com> | 2019-09-18 18:13:32 +0000 |
|---|---|---|
| committer | Dan Albert <danalbert@google.com> | 2019-09-18 18:13:32 +0000 |
| commit | 85e26f56cbf3e1ae3aed155b817912f02172bbef (patch) | |
| tree | d3e2a3990b8ccad3b5469822a6dfcc3a12b5f658 /libcxx/test/std/thread/thread.condition | |
| parent | 4b661f94e288b56f49579da2dea7a70cdf5b66e3 (diff) | |
| download | bcm5719-llvm-85e26f56cbf3e1ae3aed155b817912f02172bbef.tar.gz bcm5719-llvm-85e26f56cbf3e1ae3aed155b817912f02172bbef.zip | |
Revert "Revert "Implement std::condition_variable via pthread_cond_clockwait() where available""
With the fix for non-Linux.
This reverts commit c1c519d2f1a66dd2eeaa4c321d8d7b50f623eb71.
llvm-svn: 372242
Diffstat (limited to 'libcxx/test/std/thread/thread.condition')
| -rw-r--r-- | libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp index 12ccf3f1c06..e5c77f28eb8 100644 --- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp +++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp @@ -25,12 +25,12 @@ #include "test_macros.h" -struct Clock +struct TestClock { typedef std::chrono::milliseconds duration; typedef duration::rep rep; typedef duration::period period; - typedef std::chrono::time_point<Clock> time_point; + typedef std::chrono::time_point<TestClock> time_point; static const bool is_steady = true; static time_point now() @@ -50,35 +50,40 @@ int test2 = 0; int runs = 0; +template <typename Clock> void f() { std::unique_lock<std::mutex> lk(mut); assert(test2 == 0); test1 = 1; cv.notify_one(); - Clock::time_point t0 = Clock::now(); - Clock::time_point t = t0 + Clock::duration(250); + typename Clock::time_point t0 = Clock::now(); + typename Clock::time_point t = t0 + std::chrono::milliseconds(250); while (test2 == 0 && cv.wait_until(lk, t) == std::cv_status::no_timeout) ; - Clock::time_point t1 = Clock::now(); + typename Clock::time_point t1 = Clock::now(); if (runs == 0) { - assert(t1 - t0 < Clock::duration(250)); + assert(t1 - t0 < std::chrono::milliseconds(250)); assert(test2 != 0); } else { - assert(t1 - t0 - Clock::duration(250) < Clock::duration(50)); + assert(t1 - t0 - std::chrono::milliseconds(250) < std::chrono::milliseconds(50)); assert(test2 == 0); } ++runs; } -int main(int, char**) +template <typename Clock> +void run_test() { + runs = 0; + test1 = 0; + test2 = 0; { std::unique_lock<std::mutex>lk(mut); - std::thread t(f); + std::thread t(f<Clock>); assert(test1 == 0); while (test1 == 0) cv.wait(lk); @@ -92,7 +97,7 @@ int main(int, char**) test2 = 0; { std::unique_lock<std::mutex>lk(mut); - std::thread t(f); + std::thread t(f<Clock>); assert(test1 == 0); while (test1 == 0) cv.wait(lk); @@ -100,6 +105,12 @@ int main(int, char**) lk.unlock(); t.join(); } +} - return 0; +int main(int, char**) +{ + run_test<TestClock>(); + run_test<std::chrono::steady_clock>(); + run_test<std::chrono::system_clock>(); + return 0; } |

