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
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
15 // template <class ...Mutex> class scoped_lock;
17 // scoped_lock(Mutex&..., adopt_lock_t);
21 #include "test_macros.h"
25 TestMutex() = default;
27 void lock() { assert(!locked); locked = true; }
28 bool try_lock() { if (locked) return false; locked = true; return true; }
29 void unlock() { assert(locked); locked = false; }
31 TestMutex(TestMutex const&) = delete;
32 TestMutex& operator=(TestMutex const&) = delete;
38 using LG = std::scoped_lock<>;
39 LG lg(std::adopt_lock);
43 using LG = std::scoped_lock<TestMutex>;
46 LG lg(m1, std::adopt_lock);
53 using LG = std::scoped_lock<TestMutex, TestMutex>;
56 LG lg(m1, m2, std::adopt_lock);
57 assert(m1.locked && m2.locked);
59 assert(!m1.locked && !m2.locked);
63 using LG = std::scoped_lock<TestMutex, TestMutex, TestMutex>;
64 m1.lock(); m2.lock(); m3.lock();
66 LG lg(m1, m2, m3, std::adopt_lock);
67 assert(m1.locked && m2.locked && m3.locked);
69 assert(!m1.locked && !m2.locked && !m3.locked);