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: libcpp-has-no-threads 10 // UNSUPPORTED: c++98, c++03, c++11 11 12 // <shared_mutex> 13 14 // template <class Mutex> class shared_lock; 15 16 // mutex_type* release() noexcept; 17 18 #include <shared_mutex> 19 #include <cassert> 20 21 struct mutex 22 { 23 static int lock_count; 24 static int unlock_count; 25 void lock_shared() {++lock_count;} 26 void unlock_shared() {++unlock_count;} 27 }; 28 29 int mutex::lock_count = 0; 30 int mutex::unlock_count = 0; 31 32 mutex m; 33 34 int main(int, char**) 35 { 36 std::shared_lock<mutex> lk(m); 37 assert(lk.mutex() == &m); 38 assert(lk.owns_lock() == true); 39 assert(mutex::lock_count == 1); 40 assert(mutex::unlock_count == 0); 41 assert(lk.release() == &m); 42 assert(lk.mutex() == nullptr); 43 assert(lk.owns_lock() == false); 44 assert(mutex::lock_count == 1); 45 assert(mutex::unlock_count == 0); 46 static_assert(noexcept(lk.release()), "release must be noexcept"); 47 48 return 0; 49 } 50