[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.mutex.requirements / thread.sharedtimedmutex.requirements / thread.sharedtimedmutex.class / try_lock_until.pass.cpp
blobfb521efdb93f59db57365d542ee6801becbab4f0
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11
12 // ALLOW_RETRIES: 2
14 // <shared_mutex>
16 // class shared_timed_mutex;
18 // template <class Clock, class Duration>
19 // bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
21 #include <shared_mutex>
22 #include <thread>
23 #include <cstdlib>
24 #include <cassert>
25 #include <chrono>
27 #include "make_test_thread.h"
28 #include "test_macros.h"
30 std::shared_timed_mutex m;
32 typedef std::chrono::steady_clock Clock;
33 typedef Clock::time_point time_point;
34 typedef Clock::duration duration;
35 typedef std::chrono::milliseconds ms;
36 typedef std::chrono::nanoseconds ns;
39 ms WaitTime = ms(250);
41 // Thread sanitizer causes more overhead and will sometimes cause this test
42 // to fail. To prevent this we give Thread sanitizer more time to complete the
43 // test.
44 #if !defined(TEST_IS_EXECUTED_IN_A_SLOW_ENVIRONMENT)
45 ms Tolerance = ms(50);
46 #else
47 ms Tolerance = ms(50 * 5);
48 #endif
50 void f1()
52 time_point t0 = Clock::now();
53 assert(m.try_lock_until(Clock::now() + WaitTime + Tolerance) == true);
54 time_point t1 = Clock::now();
55 m.unlock();
56 ns d = t1 - t0 - WaitTime;
57 assert(d < Tolerance); // within tolerance
60 void f2()
62 time_point t0 = Clock::now();
63 assert(m.try_lock_until(Clock::now() + WaitTime) == false);
64 time_point t1 = Clock::now();
65 ns d = t1 - t0 - WaitTime;
66 assert(d < Tolerance); // within tolerance
69 int main(int, char**)
72 m.lock();
73 std::thread t = support::make_test_thread(f1);
74 std::this_thread::sleep_for(WaitTime);
75 m.unlock();
76 t.join();
79 m.lock();
80 std::thread t = support::make_test_thread(f2);
81 std::this_thread::sleep_for(WaitTime + Tolerance);
82 m.unlock();
83 t.join();
86 return 0;