1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11, c++14
14 // template <class ...Mutex> class scoped_lock;
16 // scoped_lock(adopt_lock_t, Mutex&...);
20 #include "test_macros.h"
24 TestMutex() = default;
26 void lock() { assert(!locked
); locked
= true; }
27 bool try_lock() { if (locked
) return false; locked
= true; return true; }
28 void unlock() { assert(locked
); locked
= false; }
30 TestMutex(TestMutex
const&) = delete;
31 TestMutex
& operator=(TestMutex
const&) = delete;
37 using LG
= std::scoped_lock
<>;
38 LG
lg(std::adopt_lock
);
42 using LG
= std::scoped_lock
<TestMutex
>;
45 LG
lg(std::adopt_lock
, m1
);
52 using LG
= std::scoped_lock
<TestMutex
, TestMutex
>;
55 LG
lg(std::adopt_lock
, m1
, m2
);
56 assert(m1
.locked
&& m2
.locked
);
58 assert(!m1
.locked
&& !m2
.locked
);
62 using LG
= std::scoped_lock
<TestMutex
, TestMutex
, TestMutex
>;
63 m1
.lock(); m2
.lock(); m3
.lock();
65 LG
lg(std::adopt_lock
, m1
, m2
, m3
);
66 assert(m1
.locked
&& m2
.locked
&& m3
.locked
);
68 assert(!m1
.locked
&& !m2
.locked
&& !m3
.locked
);