Getting <atomic> warmed back up. We have a hopefully more stable spec now. And I believe the intrinsic spec at http://libcxx.llvm.org/atomic_design_a.html is still good.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121064 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7a0248d2d7
commit
4777bf2799
3086
include/atomic
3086
include/atomic
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,88 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
volatile A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj, T* expc,
|
||||||
|
// T desr,
|
||||||
|
// memory_order s, memory_order f);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc, T desr,
|
||||||
|
// memory_order s, memory_order f);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(2),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(3),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
volatile A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(2),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(3),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_weak(&a, &t, T(2)) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_weak(&a, &t, T(3)) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
volatile A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_weak(&a, &t, T(2)) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_weak(&a, &t, T(3)) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
|
||||||
|
// T desr,
|
||||||
|
// memory_order s, memory_order f);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
|
||||||
|
// memory_order s, memory_order f);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(2),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(3),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
volatile A a;
|
||||||
|
T t(T(1));
|
||||||
|
std::atomic_init(&a, t);
|
||||||
|
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(2),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(1));
|
||||||
|
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(3),
|
||||||
|
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
|
||||||
|
assert(a == T(2));
|
||||||
|
assert(t == T(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_exchange(volatile atomic<T>* obj, T desr);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_exchange(atomic<T>* obj, T desr);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_init(&t, T(1));
|
||||||
|
assert(std::atomic_exchange(&t, T(2)) == T(1));
|
||||||
|
assert(t == T(2));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_init(&vt, T(3));
|
||||||
|
assert(std::atomic_exchange(&vt, T(4)) == T(3));
|
||||||
|
assert(vt == T(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_init(&t, T(1));
|
||||||
|
assert(std::atomic_exchange_explicit(&t, T(2), std::memory_order_seq_cst)
|
||||||
|
== T(1));
|
||||||
|
assert(t == T(2));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_init(&vt, T(3));
|
||||||
|
assert(std::atomic_exchange_explicit(&vt, T(4), std::memory_order_seq_cst)
|
||||||
|
== T(3));
|
||||||
|
assert(vt == T(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// void
|
||||||
|
// atomic_init(volatile atomic<T>* obj, T desr);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// void
|
||||||
|
// atomic_init(atomic<T>* obj, T desr);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_init(&t, T(1));
|
||||||
|
assert(t == T(1));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_init(&vt, T(2));
|
||||||
|
assert(vt == T(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_is_lock_free(const volatile atomic<T>* obj);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// bool
|
||||||
|
// atomic_is_lock_free(const atomic<T>* obj);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
const A ct;
|
||||||
|
bool b1 = std::atomic_is_lock_free(&ct);
|
||||||
|
const volatile A cvt;
|
||||||
|
bool b2 = std::atomic_is_lock_free(&cvt);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
char _[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_load(const volatile atomic<T>* obj);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_load(const atomic<T>* obj);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_init(&t, T(1));
|
||||||
|
assert(std::atomic_load(&t) == T(1));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_init(&vt, T(2));
|
||||||
|
assert(std::atomic_load(&vt) == T(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_load_explicit(const volatile atomic<T>* obj, memory_order m);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// T
|
||||||
|
// atomic_load_explicit(const atomic<T>* obj, memory_order m);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_init(&t, T(1));
|
||||||
|
assert(std::atomic_load_explicit(&t, std::memory_order_seq_cst) == T(1));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_init(&vt, T(2));
|
||||||
|
assert(std::atomic_load_explicit(&vt, std::memory_order_seq_cst) == T(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// void
|
||||||
|
// atomic_store(volatile atomic<T>* obj, T desr);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// void
|
||||||
|
// atomic_store(atomic<T>* obj, T desr);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_store(&t, T(1));
|
||||||
|
assert(t == T(1));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_store(&vt, T(2));
|
||||||
|
assert(vt == T(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <atomic>
|
||||||
|
|
||||||
|
// template <class T>
|
||||||
|
// void
|
||||||
|
// atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m);
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// void
|
||||||
|
// atomic_store_explicit(atomic<T>* obj, T desr, memory_order m);
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void
|
||||||
|
test()
|
||||||
|
{
|
||||||
|
typedef std::atomic<T> A;
|
||||||
|
A t;
|
||||||
|
std::atomic_store_explicit(&t, T(1), std::memory_order_seq_cst);
|
||||||
|
assert(t == T(1));
|
||||||
|
volatile A vt;
|
||||||
|
std::atomic_store_explicit(&vt, T(2), std::memory_order_seq_cst);
|
||||||
|
assert(vt == T(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
explicit A(int d = 0) : i(d) {}
|
||||||
|
A(const A& a) : i(a.i) {}
|
||||||
|
A(const volatile A& a) : i(a.i) {}
|
||||||
|
|
||||||
|
void operator=(const volatile A& a) volatile {i = a.i;}
|
||||||
|
|
||||||
|
friend bool operator==(const A& x, const A& y)
|
||||||
|
{return x.i == y.i;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test<A>();
|
||||||
|
test<char>();
|
||||||
|
test<signed char>();
|
||||||
|
test<unsigned char>();
|
||||||
|
test<short>();
|
||||||
|
test<unsigned short>();
|
||||||
|
test<int>();
|
||||||
|
test<unsigned int>();
|
||||||
|
test<long>();
|
||||||
|
test<unsigned long>();
|
||||||
|
test<long long>();
|
||||||
|
test<unsigned long long>();
|
||||||
|
test<wchar_t>();
|
||||||
|
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<char16_t>();
|
||||||
|
test<char32_t>();
|
||||||
|
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||||
|
test<int*>();
|
||||||
|
test<const int*>();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user