[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.lock / thread.lock.unique / thread.lock.unique.cons / mutex_duration.pass.cpp
blob4bfabab919f17792af59f54c8c2e9cd72c190c2b
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 // ALLOW_RETRIES: 2
12 // <mutex>
14 // class timed_mutex;
16 // template <class Rep, class Period>
17 // unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
19 #include <mutex>
20 #include <thread>
21 #include <cstdlib>
22 #include <cassert>
24 #include "make_test_thread.h"
25 #include "test_macros.h"
27 std::timed_mutex m;
29 typedef std::chrono::steady_clock Clock;
30 typedef Clock::time_point time_point;
31 typedef Clock::duration duration;
32 typedef std::chrono::milliseconds ms;
33 typedef std::chrono::nanoseconds ns;
35 void f1()
37 time_point t0 = Clock::now();
38 std::unique_lock<std::timed_mutex> lk(m, ms(300));
39 assert(lk.owns_lock() == true);
40 time_point t1 = Clock::now();
41 ns d = t1 - t0 - ms(250);
42 assert(d < ms(50)); // within 50ms
45 void f2()
47 time_point t0 = Clock::now();
48 std::unique_lock<std::timed_mutex> lk(m, ms(250));
49 assert(lk.owns_lock() == false);
50 time_point t1 = Clock::now();
51 ns d = t1 - t0 - ms(250);
52 assert(d < ms(50)); // within 50ms
55 int main(int, char**)
58 m.lock();
59 std::thread t = support::make_test_thread(f1);
60 std::this_thread::sleep_for(ms(250));
61 m.unlock();
62 t.join();
65 m.lock();
66 std::thread t = support::make_test_thread(f2);
67 std::this_thread::sleep_for(ms(300));
68 m.unlock();
69 t.join();
72 return 0;