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