1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: libcpp-has-no-threads
14 // template <class Mutex> class unique_lock;
21 #include "test_macros.h"
23 bool try_lock_called = false;
29 try_lock_called = !try_lock_called;
30 return try_lock_called;
39 std::unique_lock<mutex> lk(m, std::defer_lock);
40 assert(lk.try_lock() == true);
41 assert(try_lock_called == true);
42 assert(lk.owns_lock() == true);
43 #ifndef TEST_HAS_NO_EXCEPTIONS
49 catch (std::system_error& e)
51 assert(e.code().value() == EDEADLK);
55 assert(lk.try_lock() == false);
56 assert(try_lock_called == false);
57 assert(lk.owns_lock() == false);
59 #ifndef TEST_HAS_NO_EXCEPTIONS
65 catch (std::system_error& e)
67 assert(e.code().value() == EPERM);