1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: libcpp-has-no-threads
11 
12 // <atomic>
13 
14 // template <class Integral>
15 //     Integral
16 //     atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op);
17 //
18 // template <class Integral>
19 //     Integral
20 //     atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op);
21 
22 #include <atomic>
23 #include <type_traits>
24 #include <cassert>
25 
26 #include "atomic_helpers.h"
27 
28 template <class T>
29 struct TestFn {
operator ()TestFn30   void operator()() const {
31     {
32         typedef std::atomic<T> A;
33         A t;
34         std::atomic_init(&t, T(1));
35         assert(std::atomic_fetch_xor_explicit(&t, T(2),
36                std::memory_order_seq_cst) == T(1));
37         assert(t == T(3));
38     }
39     {
40         typedef std::atomic<T> A;
41         volatile A t;
42         std::atomic_init(&t, T(3));
43         assert(std::atomic_fetch_xor_explicit(&t, T(2),
44                std::memory_order_seq_cst) == T(3));
45         assert(t == T(1));
46     }
47   }
48 };
49 
main()50 int main()
51 {
52     TestEachIntegralType<TestFn>()();
53 }
54