]>
Commit | Line | Data |
---|---|---|
b7dd4edb | 1 | // { dg-options "-std=gnu++11" } |
2 | // { dg-do compile } | |
3 | ||
f1717362 | 4 | // Copyright (C) 2013-2016 Free Software Foundation, Inc. |
b7dd4edb | 5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <atomic> | |
22 | #include <testsuite_common_types.h> | |
23 | ||
24 | #define TEST_ALL_ORDERS() \ | |
25 | do { \ | |
26 | ORDER_TEST(std::memory_order_relaxed); \ | |
27 | ORDER_TEST(std::memory_order_consume); \ | |
28 | ORDER_TEST(std::memory_order_acquire); \ | |
29 | ORDER_TEST(std::memory_order_release); \ | |
30 | ORDER_TEST(std::memory_order_acq_rel); \ | |
31 | ORDER_TEST(std::memory_order_seq_cst); \ | |
32 | } while(0) | |
33 | ||
34 | void test01() | |
35 | { | |
36 | #define ORDER_TEST(ORDER) \ | |
37 | do { \ | |
38 | __gnu_test::compare_exchange_order_lowering<ORDER> test; \ | |
39 | __gnu_cxx::typelist::apply_generator(test, \ | |
40 | __gnu_test::integral_types::type()); \ | |
41 | } while (0); | |
42 | TEST_ALL_ORDERS(); | |
43 | #undef ORDER_TEST | |
44 | ||
45 | enum e { a, b, c }; | |
46 | #define ORDER_TEST(ORDER) \ | |
47 | do { \ | |
48 | std::atomic<e> x(a); \ | |
49 | e expected = a; \ | |
50 | x.compare_exchange_strong(expected, b, ORDER); \ | |
51 | x.compare_exchange_weak(expected, c, ORDER); \ | |
52 | } while (0); | |
53 | TEST_ALL_ORDERS(); | |
54 | #undef ORDER_TEST | |
55 | ||
56 | #define ORDER_TEST(ORDER) \ | |
57 | do { \ | |
58 | std::atomic<void*> x(nullptr); \ | |
59 | void* expected = nullptr; \ | |
60 | x.compare_exchange_strong(expected, nullptr, ORDER); \ | |
61 | x.compare_exchange_weak(expected, nullptr, ORDER); \ | |
62 | } while (0); | |
63 | TEST_ALL_ORDERS(); | |
64 | #undef ORDER_TEST | |
65 | } |