[libcxx-commits] [libcxx] 59fc867 - Re-split integral & pointer overloads. Add tests.
Olivier Giroux via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Sep 11 12:13:50 PDT 2020
Author: Olivier Giroux
Date: 2020-09-11T12:13:35-07:00
New Revision: 59fc86779038b19cf85f87b51052d468286788f2
URL: https://github.com/llvm/llvm-project/commit/59fc86779038b19cf85f87b51052d468286788f2
DIFF: https://github.com/llvm/llvm-project/commit/59fc86779038b19cf85f87b51052d468286788f2.diff
LOG: Re-split integral & pointer overloads. Add tests.
Added:
Modified:
libcxx/include/atomic
libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp
libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp
libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp
libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/atomic b/libcxx/include/atomic
index be81f6491edf6..56bd03584c9b4 100644
--- a/libcxx/include/atomic
+++ b/libcxx/include/atomic
@@ -2163,7 +2163,7 @@ template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op) _NOEXCEPT
@@ -2175,7 +2175,7 @@ template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op) _NOEXCEPT
@@ -2183,13 +2183,29 @@ atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op) _
return __o->fetch_add(__op);
}
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_add(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op) _NOEXCEPT
+{
+ return __o->fetch_add(__op);
+}
+
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_add(atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op) _NOEXCEPT
+{
+ return __o->fetch_add(__op);
+}
+
// atomic_fetch_add_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op, memory_order __m) _NOEXCEPT
@@ -2201,7 +2217,7 @@ template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op, memory_order __m) _NOEXCEPT
@@ -2209,13 +2225,29 @@ atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_typ
return __o->fetch_add(__op, __m);
}
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op, memory_order __m) _NOEXCEPT
+{
+ return __o->fetch_add(__op, __m);
+}
+
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_add_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op, memory_order __m) _NOEXCEPT
+{
+ return __o->fetch_add(__op, __m);
+}
+
// atomic_fetch_sub
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op) _NOEXCEPT
@@ -2227,7 +2259,7 @@ template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op) _NOEXCEPT
@@ -2235,13 +2267,29 @@ atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op) _
return __o->fetch_sub(__op);
}
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_sub(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op) _NOEXCEPT
+{
+ return __o->fetch_sub(__op);
+}
+
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_sub(atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op) _NOEXCEPT
+{
+ return __o->fetch_sub(__op);
+}
+
// atomic_fetch_sub_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op, memory_order __m) _NOEXCEPT
@@ -2253,7 +2301,7 @@ template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_pointer<_Tp>::value || (is_integral<_Tp>::value && !is_same<_Tp, bool>::value),
+ is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
_Tp
>::type
atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_type __op, memory_order __m) _NOEXCEPT
@@ -2261,6 +2309,22 @@ atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::
diff erence_typ
return __o->fetch_sub(__op, __m);
}
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op, memory_order __m) _NOEXCEPT
+{
+ return __o->fetch_sub(__op, __m);
+}
+
+template <class _Tp>
+_LIBCPP_INLINE_VISIBILITY
+_Tp*
+atomic_fetch_sub_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::
diff erence_type __op, memory_order __m) _NOEXCEPT
+{
+ return __o->fetch_sub(__op, __m);
+}
+
// atomic_fetch_and
template <class _Tp>
diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp
index e584ea955d754..38ce06e2817b5 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp
@@ -63,6 +63,7 @@ void testp()
A t;
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add(&t, 2) == T(1*sizeof(X)));
+ std::atomic_fetch_add<X>(&t, 0);
assert(t == T(3*sizeof(X)));
}
{
@@ -71,6 +72,7 @@ void testp()
volatile A t;
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add(&t, 2) == T(1*sizeof(X)));
+ std::atomic_fetch_add<X>(&t, 0);
assert(t == T(3*sizeof(X)));
}
}
diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp
index 548101a409e9e..f39adb14effac 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp
@@ -67,6 +67,7 @@ testp()
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add_explicit(&t, 2,
std::memory_order_seq_cst) == T(1*sizeof(X)));
+ std::atomic_fetch_add_explicit<X>(&t, 0, std::memory_order_relaxed);
assert(t == T(3*sizeof(X)));
}
{
@@ -76,6 +77,7 @@ testp()
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add_explicit(&t, 2,
std::memory_order_seq_cst) == T(1*sizeof(X)));
+ std::atomic_fetch_add_explicit<X>(&t, 0, std::memory_order_relaxed);
assert(t == T(3*sizeof(X)));
}
}
diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp
index 20ec7688bb2ba..3568d2fa60ff6 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp
@@ -63,6 +63,7 @@ void testp()
A t;
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub(&t, 2) == T(3*sizeof(X)));
+ std::atomic_fetch_sub<X>(&t, 0);
assert(t == T(1*sizeof(X)));
}
{
@@ -71,6 +72,7 @@ void testp()
volatile A t;
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub(&t, 2) == T(3*sizeof(X)));
+ std::atomic_fetch_sub<X>(&t, 0);
assert(t == T(1*sizeof(X)));
}
}
diff --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp
index f26cefcbdb074..261917f8087e0 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp
@@ -67,6 +67,7 @@ void testp()
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub_explicit(&t, 2,
std::memory_order_seq_cst) == T(3*sizeof(X)));
+ std::atomic_fetch_sub_explicit<X>(&t, 0, std::memory_order_relaxed);
assert(t == T(1*sizeof(X)));
}
{
@@ -76,6 +77,7 @@ void testp()
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub_explicit(&t, 2,
std::memory_order_seq_cst) == T(3*sizeof(X)));
+ std::atomic_fetch_sub_explicit<X>(&t, 0, std::memory_order_relaxed);
assert(t == T(1*sizeof(X)));
}
}
More information about the libcxx-commits
mailing list