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 // void unlock(); 17 18 #include <shared_mutex> 19 #include <cassert> 20 21 #include "test_macros.h" 22 23 bool unlock_called = false; 24 25 struct mutex 26 { 27 void lock_shared() {} 28 void unlock_shared() {unlock_called = true;} 29 }; 30 31 mutex m; 32 33 int main(int, char**) 34 { 35 std::shared_lock<mutex> lk(m); 36 lk.unlock(); 37 assert(unlock_called == true); 38 assert(lk.owns_lock() == false); 39 #ifndef TEST_HAS_NO_EXCEPTIONS 40 try 41 { 42 lk.unlock(); 43 assert(false); 44 } 45 catch (std::system_error& e) 46 { 47 assert(e.code().value() == EPERM); 48 } 49 #endif 50 lk.release(); 51 #ifndef TEST_HAS_NO_EXCEPTIONS 52 try 53 { 54 lk.unlock(); 55 assert(false); 56 } 57 catch (std::system_error& e) 58 { 59 assert(e.code().value() == EPERM); 60 } 61 #endif 62 63 return 0; 64 } 65