Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Refine constraints and change test to reflect that
Browse files Browse the repository at this point in the history
  • Loading branch information
wmaxey committed Oct 28, 2021
1 parent ab88964 commit 8169019
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// <cuda/std/atomic>

#include <cuda/std/atomic>
#include <cuda/std/utility>
#include <cuda/std/cassert>
// #include <cuda/std/thread> // for thread_id
// #include <cuda/std/chrono> // for nanoseconds
Expand All @@ -25,13 +26,19 @@
template <class T>
__host__ __device__
void test_not_copy_constructible() {
static_assert(!cuda::std::is_copy_constructible<T>(), "");
static_assert(!cuda::std::is_constructible<T, T&&>(), "");
static_assert(!cuda::std::is_constructible<T, const T&>(), "");
static_assert(!cuda::std::is_assignable<T, T&&>(), "");
static_assert(!cuda::std::is_assignable<T, const T&>(), "");
}

template <class T>
__host__ __device__
void test_copy_constructible() {
static_assert(cuda::std::is_copy_constructible<T>(), "");
static_assert(cuda::std::is_constructible<T, T&&>(), "");
static_assert(cuda::std::is_constructible<T, const T&>(), "");
static_assert(!cuda::std::is_assignable<T, T&&>(), "");
static_assert(!cuda::std::is_assignable<T, const T&>(), "");
}

template <class T, class A>
Expand All @@ -48,22 +55,38 @@ void test_atomic_ref_copy_ctor() {
assert(t1.load() == 2);
}

template <class T, class A>
__host__ __device__
void test_atomic_ref_move_ctor() {
A val = 0;

T t0(val);
t0++;

T t1(cuda::std::move(t0));
t1++;

assert(t1.load() == 2);
}

int main(int, char**)
{
test_not_copy_constructible<cuda::std::atomic<int>>();
test_not_copy_constructible<cuda::atomic<int>>();
test_not_copy_constructible<const cuda::std::atomic<int>>();
test_not_copy_constructible<const cuda::atomic<int>>();


test_copy_constructible<cuda::std::atomic_ref<int>>();
test_copy_constructible<cuda::atomic_ref<int>>();
test_copy_constructible<const cuda::std::atomic_ref<int>>();
test_copy_constructible<const cuda::atomic_ref<int>>();

test_atomic_ref_copy_ctor<cuda::std::atomic_ref<int>, int>();
test_atomic_ref_copy_ctor<cuda::atomic_ref<int>, int>();
test_atomic_ref_copy_ctor<const cuda::std::atomic_ref<int>, int>();
test_atomic_ref_copy_ctor<const cuda::atomic_ref<int>, int>();

test_atomic_ref_move_ctor<cuda::std::atomic_ref<int>, int>();
test_atomic_ref_move_ctor<cuda::atomic_ref<int>, int>();
test_atomic_ref_move_ctor<const cuda::std::atomic_ref<int>, int>();
test_atomic_ref_move_ctor<const cuda::atomic_ref<int>, int>();
// test(cuda::std::this_thread::get_id());
// test(cuda::std::chrono::nanoseconds(2));

Expand Down
25 changes: 18 additions & 7 deletions include/cuda/std/detail/libcxx/include/atomic
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,11 @@ struct __atomic_base {

__atomic_base() = default;
__atomic_base(const __atomic_base&) = delete;
__atomic_base(__atomic_base&&) = delete;

__atomic_base& operator=(const __atomic_base&) = delete;
__atomic_base& operator=(__atomic_base&&) = delete;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR
__atomic_base(const _Tp& __a) _NOEXCEPT : __a_(__a) {}

Expand Down Expand Up @@ -1366,14 +1371,18 @@ struct __atomic_base_ref {

__atomic_base_ref() = default;
__atomic_base_ref(const __atomic_base_ref&) = default;
__atomic_base_ref(__atomic_base_ref&&) = default;

__atomic_base_ref& operator=(const __atomic_base_ref&) = delete;
__atomic_base_ref& operator=(__atomic_base_ref&&) = delete;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR
__atomic_base_ref(_Tp& __a) _NOEXCEPT : __a_(__a) {}

#if defined(_LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE)
static _LIBCUDACXX_CONSTEXPR bool is_always_lock_free = _LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE(sizeof(decltype(__a_)), 0);
#endif // defined(_LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE)


_LIBCUDACXX_INLINE_VISIBILITY
bool is_lock_free() const volatile _NOEXCEPT
{return __cxx_atomic_is_lock_free(sizeof(_Tp));}
Expand Down Expand Up @@ -1486,6 +1495,10 @@ template <class _Tp, int _Sco>
struct __atomic_base<_Tp, _Sco, true> : public __atomic_base<_Tp, _Sco, false> {
__atomic_base() = default;
__atomic_base(const __atomic_base&) = delete;
__atomic_base(__atomic_base&&) = delete;

__atomic_base& operator=(const __atomic_base&) = delete;
__atomic_base& operator=(__atomic_base&&) = delete;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR
__atomic_base(const _Tp& __a) _NOEXCEPT : __atomic_base<_Tp, _Sco, false>(__a) {}
Expand Down Expand Up @@ -1563,6 +1576,10 @@ template <class _Tp, int _Sco>
struct __atomic_base_ref<_Tp, _Sco, true> : public __atomic_base_ref<_Tp, _Sco, false> {
__atomic_base_ref() = default;
__atomic_base_ref(const __atomic_base_ref&) = default;
__atomic_base_ref(__atomic_base_ref&&) = default;

__atomic_base_ref& operator=(const __atomic_base_ref&) = delete;
__atomic_base_ref& operator=(__atomic_base_ref&&) = delete;

_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR
__atomic_base_ref(_Tp& __a) _NOEXCEPT : __atomic_base_ref<_Tp, _Sco, false>(__a) {}
Expand Down Expand Up @@ -1748,9 +1765,6 @@ template <class _Tp>
_LIBCUDACXX_INLINE_VISIBILITY
explicit atomic_ref(_Tp& __ref) : __base(__ref) {}

atomic_ref(const atomic_ref&) noexcept = default;
atomic_ref& operator=(const atomic_ref&) = delete;

_LIBCUDACXX_INLINE_VISIBILITY
_Tp operator=(_Tp __v) const noexcept {__base::store(__v); return __v;}
_LIBCUDACXX_INLINE_VISIBILITY
Expand All @@ -1773,9 +1787,6 @@ template <class _Tp>
_LIBCUDACXX_INLINE_VISIBILITY
explicit atomic_ref(_Tp*& __ref) : __base(__ref) {}

atomic_ref(const atomic_ref&) noexcept = default;
atomic_ref& operator=(const atomic_ref&) = delete;

_LIBCUDACXX_INLINE_VISIBILITY
_Tp* operator=(_Tp* __v) const noexcept {__base::store(__v); return __v;}
_LIBCUDACXX_INLINE_VISIBILITY
Expand Down

0 comments on commit 8169019

Please sign in to comment.