Skip to content

Commit 7def396

Browse files
committed
[libc++][atomic_ref] Attempt to use __cxx_atomic_wait
1 parent b5d55f2 commit 7def396

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

libcxx/include/__atomic/atomic_ref.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define _LIBCPP___ATOMIC_ATOMIC_REF_H
1919

2020
#include <__assert>
21+
#include <__atomic/atomic_sync.h>
2122
#include <__atomic/check_memory_order.h>
2223
#include <__atomic/to_gcc_order.h>
2324
#include <__config>
@@ -143,16 +144,10 @@ struct __atomic_ref_base {
143144
__order == memory_order::relaxed || __order == memory_order::consume || __order == memory_order::acquire ||
144145
__order == memory_order::seq_cst,
145146
"memory order argument to atomic wait operation is invalid");
146-
// FIXME
147-
(void)__old;
148-
(void)__order;
149-
}
150-
_LIBCPP_HIDE_FROM_ABI void notify_one() const noexcept {
151-
// FIXME
152-
}
153-
_LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept {
154-
// FIXME
147+
__cxx_atomic_wait(__ptr_, __old, __order);
155148
}
149+
_LIBCPP_HIDE_FROM_ABI void notify_one() const noexcept { __cxx_atomic_notify_one(__ptr_); }
150+
_LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { __cxx_atomic_notify_all(__ptr_); }
156151

157152
_LIBCPP_HIDE_FROM_ABI __atomic_ref_base(_Tp& __obj) : __ptr_(&__obj) {}
158153
};

libcxx/include/__atomic/atomic_sync.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727

2828
_LIBCPP_BEGIN_NAMESPACE_STD
2929

30+
template <class _Tp>
31+
struct __is_cxx_atomic_impl : false_type {};
32+
33+
template <class _Tp>
34+
struct __is_cxx_atomic_impl<__cxx_atomic_impl<_Tp> > : true_type {};
35+
36+
template <class _Tp>
37+
_LIBCPP_HIDE_FROM_ABI __enable_if_t<!__is_cxx_atomic_impl<__remove_cv_t<_Tp> >::value, _Tp>
38+
__cxx_atomic_load(_Tp* __ptr, memory_order __order) noexcept {
39+
alignas(_Tp) unsigned char __mem[sizeof(_Tp)];
40+
auto* __ret = reinterpret_cast<_Tp*>(__mem);
41+
__atomic_load(__ptr, __ret, __to_gcc_order(__order));
42+
return *__ret;
43+
}
44+
3045
#ifndef _LIBCPP_HAS_NO_THREADS
3146

3247
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*);

libcxx/test/std/atomics/atomics.ref/notify_all.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//===----------------------------------------------------------------------===//
77

88
// UNSUPPORTED: c++03, c++11, c++14, c++17
9-
// XFAIL: *
109

1110
// void notify_all() const noexcept;
1211

libcxx/test/std/atomics/atomics.ref/notify_one.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//===----------------------------------------------------------------------===//
77

88
// UNSUPPORTED: c++03, c++11, c++14, c++17
9-
// XFAIL: *
109

1110
// void notify_one() const noexcept;
1211

libcxx/test/std/atomics/atomics.ref/wait.pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//===----------------------------------------------------------------------===//
77

88
// UNSUPPORTED: c++03, c++11, c++14, c++17
9-
// XFAIL: *
109

1110
// void wait(T, memory_order = memory_order::seq_cst) const noexcept;
1211

0 commit comments

Comments
 (0)