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