1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // UNSUPPORTED: libcpp-has-no-threads 11 12 // <mutex> 13 14 // template <class Mutex> class unique_lock; 15 16 // void unlock(); 17 18 #include <mutex> 19 #include <cassert> 20 21 #include "test_macros.h" 22 23 bool unlock_called = false; 24 25 struct mutex 26 { lockmutex27 void lock() {} unlockmutex28 void unlock() {unlock_called = true;} 29 }; 30 31 mutex m; 32 main()33int main() 34 { 35 std::unique_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