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
14 // template <class Mutex> class shared_lock;
16 // mutex_type* release() noexcept;
18 #include <shared_mutex>
21 #include "test_macros.h"
25 static int lock_count
;
26 static int unlock_count
;
27 void lock_shared() {++lock_count
;}
28 void unlock_shared() {++unlock_count
;}
31 int mutex::lock_count
= 0;
32 int mutex::unlock_count
= 0;
38 std::shared_lock
<mutex
> lk(m
);
39 assert(lk
.mutex() == &m
);
40 assert(lk
.owns_lock() == true);
41 assert(mutex::lock_count
== 1);
42 assert(mutex::unlock_count
== 0);
43 assert(lk
.release() == &m
);
44 assert(lk
.mutex() == nullptr);
45 assert(lk
.owns_lock() == false);
46 assert(mutex::lock_count
== 1);
47 assert(mutex::unlock_count
== 0);
48 static_assert(noexcept(lk
.release()), "release must be noexcept");