[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.lock / thread.lock.shared / thread.lock.shared.locking / try_lock_until.pass.cpp
blob880bf1cbd499909641b5ceea0dacfe035e69bec3
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 // <shared_mutex>
14 // template <class Mutex> class shared_lock;
16 // template <class Clock, class Duration>
17 // bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
19 #include <cassert>
20 #include <chrono>
21 #include <mutex>
22 #include <shared_mutex>
23 #include <system_error>
25 #include "test_macros.h"
27 bool try_lock_until_called = false;
29 struct mutex
31 template <class Clock, class Duration>
32 bool try_lock_shared_until(const std::chrono::time_point<Clock, Duration>& abs_time)
34 typedef std::chrono::milliseconds ms;
35 assert(Clock::now() - abs_time < ms(5));
36 try_lock_until_called = !try_lock_until_called;
37 return try_lock_until_called;
39 void unlock_shared() {}
42 mutex m;
44 int main(int, char**)
46 typedef std::chrono::steady_clock Clock;
47 std::shared_lock<mutex> lk(m, std::defer_lock);
48 assert(lk.try_lock_until(Clock::now()) == true);
49 assert(try_lock_until_called == true);
50 assert(lk.owns_lock() == true);
51 #ifndef TEST_HAS_NO_EXCEPTIONS
52 try
54 TEST_IGNORE_NODISCARD lk.try_lock_until(Clock::now());
55 assert(false);
57 catch (std::system_error& e)
59 assert(e.code().value() == EDEADLK);
61 #endif
62 lk.unlock();
63 assert(lk.try_lock_until(Clock::now()) == false);
64 assert(try_lock_until_called == false);
65 assert(lk.owns_lock() == false);
66 lk.release();
67 #ifndef TEST_HAS_NO_EXCEPTIONS
68 try
70 TEST_IGNORE_NODISCARD lk.try_lock_until(Clock::now());
71 assert(false);
73 catch (std::system_error& e)
75 assert(e.code().value() == EPERM);
77 #endif
79 return 0;