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++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 #include "test_macros.h" 22 23 struct mutex 24 { 25 static int lock_count; 26 static int unlock_count; lock_sharedmutex27 void lock_shared() {++lock_count;} unlock_sharedmutex28 void unlock_shared() {++unlock_count;} 29 }; 30 31 int mutex::lock_count = 0; 32 int mutex::unlock_count = 0; 33 34 mutex m; 35 main(int,char **)36int main(int, char**) 37 { 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"); 49 50 return 0; 51 } 52