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