1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11
16 // template <class Mutex> class shared_lock;
22 #include <shared_mutex>
23 #include <system_error>
25 #include "test_macros.h"
27 bool try_lock_called
= false;
31 bool try_lock_shared()
33 try_lock_called
= !try_lock_called
;
34 return try_lock_called
;
36 void unlock_shared() {}
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
50 TEST_IGNORE_NODISCARD lk
.try_lock();
53 catch (std::system_error
& e
)
55 assert(e
.code().value() == EDEADLK
);
59 assert(lk
.try_lock() == false);
60 assert(try_lock_called
== false);
61 assert(lk
.owns_lock() == false);
63 #ifndef TEST_HAS_NO_EXCEPTIONS
66 TEST_IGNORE_NODISCARD lk
.try_lock();
69 catch (std::system_error
& e
)
71 assert(e
.code().value() == EPERM
);