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: libcpp-has-no-threads
11 // This test hangs forever when built against libstdc++ and MSVC. In order to allow
12 // validation of the test suite against other STLs we have to mark it
14 // UNSUPPORTED: libstdc++, msvc
18 // template <class L1, class L2, class... L3>
19 // void lock(L1&, L2&, L3&...);
24 #include "test_macros.h"
31 L0() : locked_(false) {}
44 void unlock() {locked_
= false;}
46 bool locked() const {return locked_
;}
54 L1() : locked_(false) {}
67 void unlock() {locked_
= false;}
69 bool locked() const {return locked_
;}
77 L2() : locked_(false) {}
90 void unlock() {locked_
= false;}
92 bool locked() const {return locked_
;}
118 #ifndef TEST_HAS_NO_EXCEPTIONS
129 assert(!l0
.locked());
130 assert(!l1
.locked());
143 assert(!l0
.locked());
144 assert(!l1
.locked());
157 assert(!l0
.locked());
158 assert(!l1
.locked());
171 assert(!l0
.locked());
172 assert(!l1
.locked());
185 assert(!l0
.locked());
186 assert(!l1
.locked());
190 #if TEST_STD_VER >= 11
195 std::lock(l0
, l1
, l2
);
200 #ifndef TEST_HAS_NO_EXCEPTIONS
207 std::lock(l0
, l1
, l2
);
212 assert(!l0
.locked());
213 assert(!l1
.locked());
214 assert(!l2
.locked());
222 std::lock(l0
, l1
, l2
);
231 std::lock(l0
, l1
, l2
);
240 std::lock(l0
, l1
, l2
);
245 #ifndef TEST_HAS_NO_EXCEPTIONS
252 std::lock(l0
, l1
, l2
);
257 assert(!l0
.locked());
258 assert(!l1
.locked());
259 assert(!l2
.locked());
268 std::lock(l0
, l1
, l2
);
273 assert(!l0
.locked());
274 assert(!l1
.locked());
275 assert(!l2
.locked());
284 std::lock(l0
, l1
, l2
);
289 assert(!l0
.locked());
290 assert(!l1
.locked());
291 assert(!l2
.locked());
300 std::lock(l0
, l1
, l2
);
305 assert(!l0
.locked());
306 assert(!l1
.locked());
307 assert(!l2
.locked());
316 std::lock(l0
, l1
, l2
);
321 assert(!l0
.locked());
322 assert(!l1
.locked());
323 assert(!l2
.locked());
332 std::lock(l0
, l1
, l2
);
337 assert(!l0
.locked());
338 assert(!l1
.locked());
339 assert(!l2
.locked());
348 std::lock(l0
, l1
, l2
);
353 assert(!l0
.locked());
354 assert(!l1
.locked());
355 assert(!l2
.locked());
364 std::lock(l0
, l1
, l2
);
369 assert(!l0
.locked());
370 assert(!l1
.locked());
371 assert(!l2
.locked());
380 std::lock(l0
, l1
, l2
);
385 assert(!l0
.locked());
386 assert(!l1
.locked());
387 assert(!l2
.locked());
390 #endif // TEST_HAS_NO_EXCEPTIONS
396 std::lock(l0
, l1
, l2
, l3
);
407 std::lock(l0
, l1
, l2
, l3
);
418 std::lock(l0
, l1
, l2
, l3
);
429 std::lock(l0
, l1
, l2
, l3
);
440 std::lock(l0
, l1
, l2
, l3
);
446 #ifndef TEST_HAS_NO_EXCEPTIONS
454 std::lock(l0
, l1
, l2
, l3
);
459 assert(!l0
.locked());
460 assert(!l1
.locked());
461 assert(!l2
.locked());
462 assert(!l3
.locked());
472 std::lock(l0
, l1
, l2
, l3
);
477 assert(!l0
.locked());
478 assert(!l1
.locked());
479 assert(!l2
.locked());
480 assert(!l3
.locked());
490 std::lock(l0
, l1
, l2
, l3
);
495 assert(!l0
.locked());
496 assert(!l1
.locked());
497 assert(!l2
.locked());
498 assert(!l3
.locked());
508 std::lock(l0
, l1
, l2
, l3
);
513 assert(!l0
.locked());
514 assert(!l1
.locked());
515 assert(!l2
.locked());
516 assert(!l3
.locked());
519 #endif // TEST_HAS_NO_EXCEPTIONS
520 #endif // TEST_STD_VER >= 11