From e8af42d76f295e7132da5d517e56bec705701a8c Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sun, 24 Dec 2023 13:57:33 -0500 Subject: [PATCH] All atomic exchanges with _Api_level should be acq_rel As _Api_level is not always accessed with sequential ordering, and _Level is thread-local, acq_rel is good enough for all compare_exchange successes. However, this means we need to explicitly mention acquire for the failure case. --- stl/src/atomic_wait.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stl/src/atomic_wait.cpp b/stl/src/atomic_wait.cpp index 2434453302..123e8dcf57 100644 --- a/stl/src/atomic_wait.cpp +++ b/stl/src/atomic_wait.cpp @@ -119,7 +119,8 @@ namespace { void _Force_wait_functions_srwlock_only() noexcept { auto _Local = _Wait_functions._Api_level.load(_STD memory_order_acquire); if (_Local <= __std_atomic_api_level::__detecting) { - while (!_Wait_functions._Api_level.compare_exchange_weak(_Local, __std_atomic_api_level::__has_srwlock)) { + while (!_Wait_functions._Api_level.compare_exchange_weak( + _Local, __std_atomic_api_level::__has_srwlock, _STD memory_order_acq_rel)) { if (_Local > __std_atomic_api_level::__detecting) { return; } @@ -128,7 +129,8 @@ namespace { } [[nodiscard]] __std_atomic_api_level _Init_wait_functions(__std_atomic_api_level _Level) { - while (!_Wait_functions._Api_level.compare_exchange_weak(_Level, __std_atomic_api_level::__detecting)) { + while (!_Wait_functions._Api_level.compare_exchange_weak( + _Level, __std_atomic_api_level::__detecting, _STD memory_order_acq_rel)) { if (_Level > __std_atomic_api_level::__detecting) { return _Level; }