[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.lock.algorithm / lock.pass.cpp
blob207b0753e7262933d60fa863acb7dcd96b021ae5
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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
13 // unsupported.
14 // UNSUPPORTED: libstdc++, msvc
16 // <mutex>
18 // template <class L1, class L2, class... L3>
19 // void lock(L1&, L2&, L3&...);
21 #include <mutex>
22 #include <cassert>
24 #include "test_macros.h"
26 class L0
28 bool locked_;
30 public:
31 L0() : locked_(false) {}
33 void lock()
35 locked_ = true;
38 bool try_lock()
40 locked_ = true;
41 return locked_;
44 void unlock() {locked_ = false;}
46 bool locked() const {return locked_;}
49 class L1
51 bool locked_;
53 public:
54 L1() : locked_(false) {}
56 void lock()
58 locked_ = true;
61 bool try_lock()
63 locked_ = false;
64 return locked_;
67 void unlock() {locked_ = false;}
69 bool locked() const {return locked_;}
72 class L2
74 bool locked_;
76 public:
77 L2() : locked_(false) {}
79 void lock()
81 TEST_THROW(1);
84 bool try_lock()
86 TEST_THROW(1);
87 return locked_;
90 void unlock() {locked_ = false;}
92 bool locked() const {return locked_;}
95 int main(int, char**)
98 L0 l0;
99 L0 l1;
100 std::lock(l0, l1);
101 assert(l0.locked());
102 assert(l1.locked());
105 L0 l0;
106 L1 l1;
107 std::lock(l0, l1);
108 assert(l0.locked());
109 assert(l1.locked());
112 L1 l0;
113 L0 l1;
114 std::lock(l0, l1);
115 assert(l0.locked());
116 assert(l1.locked());
118 #ifndef TEST_HAS_NO_EXCEPTIONS
120 L0 l0;
121 L2 l1;
124 std::lock(l0, l1);
125 assert(false);
127 catch (int)
129 assert(!l0.locked());
130 assert(!l1.locked());
134 L2 l0;
135 L0 l1;
138 std::lock(l0, l1);
139 assert(false);
141 catch (int)
143 assert(!l0.locked());
144 assert(!l1.locked());
148 L1 l0;
149 L2 l1;
152 std::lock(l0, l1);
153 assert(false);
155 catch (int)
157 assert(!l0.locked());
158 assert(!l1.locked());
162 L2 l0;
163 L1 l1;
166 std::lock(l0, l1);
167 assert(false);
169 catch (int)
171 assert(!l0.locked());
172 assert(!l1.locked());
176 L2 l0;
177 L2 l1;
180 std::lock(l0, l1);
181 assert(false);
183 catch (int)
185 assert(!l0.locked());
186 assert(!l1.locked());
189 #endif
190 #if TEST_STD_VER >= 11
192 L0 l0;
193 L0 l1;
194 L0 l2;
195 std::lock(l0, l1, l2);
196 assert(l0.locked());
197 assert(l1.locked());
198 assert(l2.locked());
200 #ifndef TEST_HAS_NO_EXCEPTIONS
202 L2 l0;
203 L2 l1;
204 L2 l2;
207 std::lock(l0, l1, l2);
208 assert(false);
210 catch (int)
212 assert(!l0.locked());
213 assert(!l1.locked());
214 assert(!l2.locked());
217 #endif
219 L0 l0;
220 L0 l1;
221 L1 l2;
222 std::lock(l0, l1, l2);
223 assert(l0.locked());
224 assert(l1.locked());
225 assert(l2.locked());
228 L0 l0;
229 L1 l1;
230 L0 l2;
231 std::lock(l0, l1, l2);
232 assert(l0.locked());
233 assert(l1.locked());
234 assert(l2.locked());
237 L1 l0;
238 L0 l1;
239 L0 l2;
240 std::lock(l0, l1, l2);
241 assert(l0.locked());
242 assert(l1.locked());
243 assert(l2.locked());
245 #ifndef TEST_HAS_NO_EXCEPTIONS
247 L0 l0;
248 L0 l1;
249 L2 l2;
252 std::lock(l0, l1, l2);
253 assert(false);
255 catch (int)
257 assert(!l0.locked());
258 assert(!l1.locked());
259 assert(!l2.locked());
263 L0 l0;
264 L2 l1;
265 L0 l2;
268 std::lock(l0, l1, l2);
269 assert(false);
271 catch (int)
273 assert(!l0.locked());
274 assert(!l1.locked());
275 assert(!l2.locked());
279 L2 l0;
280 L0 l1;
281 L0 l2;
284 std::lock(l0, l1, l2);
285 assert(false);
287 catch (int)
289 assert(!l0.locked());
290 assert(!l1.locked());
291 assert(!l2.locked());
295 L2 l0;
296 L2 l1;
297 L0 l2;
300 std::lock(l0, l1, l2);
301 assert(false);
303 catch (int)
305 assert(!l0.locked());
306 assert(!l1.locked());
307 assert(!l2.locked());
311 L2 l0;
312 L0 l1;
313 L2 l2;
316 std::lock(l0, l1, l2);
317 assert(false);
319 catch (int)
321 assert(!l0.locked());
322 assert(!l1.locked());
323 assert(!l2.locked());
327 L0 l0;
328 L2 l1;
329 L2 l2;
332 std::lock(l0, l1, l2);
333 assert(false);
335 catch (int)
337 assert(!l0.locked());
338 assert(!l1.locked());
339 assert(!l2.locked());
343 L2 l0;
344 L2 l1;
345 L1 l2;
348 std::lock(l0, l1, l2);
349 assert(false);
351 catch (int)
353 assert(!l0.locked());
354 assert(!l1.locked());
355 assert(!l2.locked());
359 L2 l0;
360 L1 l1;
361 L2 l2;
364 std::lock(l0, l1, l2);
365 assert(false);
367 catch (int)
369 assert(!l0.locked());
370 assert(!l1.locked());
371 assert(!l2.locked());
375 L1 l0;
376 L2 l1;
377 L2 l2;
380 std::lock(l0, l1, l2);
381 assert(false);
383 catch (int)
385 assert(!l0.locked());
386 assert(!l1.locked());
387 assert(!l2.locked());
390 #endif // TEST_HAS_NO_EXCEPTIONS
392 L0 l0;
393 L0 l1;
394 L0 l2;
395 L0 l3;
396 std::lock(l0, l1, l2, l3);
397 assert(l0.locked());
398 assert(l1.locked());
399 assert(l2.locked());
400 assert(l3.locked());
403 L0 l0;
404 L0 l1;
405 L0 l2;
406 L1 l3;
407 std::lock(l0, l1, l2, l3);
408 assert(l0.locked());
409 assert(l1.locked());
410 assert(l2.locked());
411 assert(l3.locked());
414 L0 l0;
415 L0 l1;
416 L1 l2;
417 L0 l3;
418 std::lock(l0, l1, l2, l3);
419 assert(l0.locked());
420 assert(l1.locked());
421 assert(l2.locked());
422 assert(l3.locked());
425 L0 l0;
426 L1 l1;
427 L0 l2;
428 L0 l3;
429 std::lock(l0, l1, l2, l3);
430 assert(l0.locked());
431 assert(l1.locked());
432 assert(l2.locked());
433 assert(l3.locked());
436 L1 l0;
437 L0 l1;
438 L0 l2;
439 L0 l3;
440 std::lock(l0, l1, l2, l3);
441 assert(l0.locked());
442 assert(l1.locked());
443 assert(l2.locked());
444 assert(l3.locked());
446 #ifndef TEST_HAS_NO_EXCEPTIONS
448 L0 l0;
449 L0 l1;
450 L0 l2;
451 L2 l3;
454 std::lock(l0, l1, l2, l3);
455 assert(false);
457 catch (int)
459 assert(!l0.locked());
460 assert(!l1.locked());
461 assert(!l2.locked());
462 assert(!l3.locked());
466 L0 l0;
467 L0 l1;
468 L2 l2;
469 L0 l3;
472 std::lock(l0, l1, l2, l3);
473 assert(false);
475 catch (int)
477 assert(!l0.locked());
478 assert(!l1.locked());
479 assert(!l2.locked());
480 assert(!l3.locked());
484 L0 l0;
485 L2 l1;
486 L0 l2;
487 L0 l3;
490 std::lock(l0, l1, l2, l3);
491 assert(false);
493 catch (int)
495 assert(!l0.locked());
496 assert(!l1.locked());
497 assert(!l2.locked());
498 assert(!l3.locked());
502 L2 l0;
503 L0 l1;
504 L0 l2;
505 L0 l3;
508 std::lock(l0, l1, l2, l3);
509 assert(false);
511 catch (int)
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
522 return 0;