[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.pass.cpp
blob0e707fcf2d50a020f2799458ac854132af8d0cdf
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 // template <class Mutex> class shared_lock;
18 // bool try_lock();
20 #include <cassert>
21 #include <mutex>
22 #include <shared_mutex>
23 #include <system_error>
25 #include "test_macros.h"
27 bool try_lock_called = false;
29 struct mutex
31 bool try_lock_shared()
33 try_lock_called = !try_lock_called;
34 return try_lock_called;
36 void unlock_shared() {}
39 mutex m;
41 int main(int, char**)
43 std::shared_lock<mutex> lk(m, std::defer_lock);
44 assert(lk.try_lock() == true);
45 assert(try_lock_called == true);
46 assert(lk.owns_lock() == true);
47 #ifndef TEST_HAS_NO_EXCEPTIONS
48 try
50 TEST_IGNORE_NODISCARD lk.try_lock();
51 assert(false);
53 catch (std::system_error& e)
55 assert(e.code().value() == EDEADLK);
57 #endif
58 lk.unlock();
59 assert(lk.try_lock() == false);
60 assert(try_lock_called == false);
61 assert(lk.owns_lock() == false);
62 lk.release();
63 #ifndef TEST_HAS_NO_EXCEPTIONS
64 try
66 TEST_IGNORE_NODISCARD lk.try_lock();
67 assert(false);
69 catch (std::system_error& e)
71 assert(e.code().value() == EPERM);
73 #endif
75 return 0;