Skip to content

Commit 290927e

Browse files
committed
[libc++] fix atomic::wait memory order
1 parent 20fbbd7 commit 290927e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libcxx/src/atomic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ __libcpp_contention_monitor_for_wait(__cxx_atomic_contention_t volatile* /*__con
151151
static void __libcpp_contention_wait(__cxx_atomic_contention_t volatile* __contention_state,
152152
__cxx_atomic_contention_t const volatile* __platform_state,
153153
__cxx_contention_t __old_value) {
154-
__cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_seq_cst);
154+
__cxx_atomic_fetch_add(__contention_state, __cxx_contention_t(1), memory_order_relaxed);
155155
// We sleep as long as the monitored value hasn't changed.
156+
__cxx_atomic_thread_fence(memory_order_seq_cst);
156157
__libcpp_platform_wait_on_address(__platform_state, __old_value);
157158
__cxx_atomic_fetch_sub(__contention_state, __cxx_contention_t(1), memory_order_release);
158159
}
@@ -163,7 +164,7 @@ static void __libcpp_contention_wait(__cxx_atomic_contention_t volatile* __conte
163164
static void __libcpp_atomic_notify(void const volatile* __location) {
164165
auto const __entry = __libcpp_contention_state(__location);
165166
// The value sequence laundering happens on the next line below.
166-
__cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_release);
167+
__cxx_atomic_fetch_add(&__entry->__platform_state, __cxx_contention_t(1), memory_order_seq_cst);
167168
__libcpp_contention_notify(
168169
&__entry->__contention_state,
169170
&__entry->__platform_state,

0 commit comments

Comments
 (0)