Atomic guard impromenents (#9473)

* Read atomic before doing CAS in the constructor.

* Typo

* Code style fix.

Co-authored-by: Roman Slivinskyi <rsl@keepit.com>
This commit is contained in:
Roman Slivinskyi 2022-01-11 11:33:36 +02:00 committed by GitHub
parent ef390902ec
commit c634f105e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ class AtomicGuard {
public:
AtomicGuard(std::atomic_bool& b) : m_atomic(b) {
bool exp = false;
while (!m_atomic.compare_exchange_strong(exp, true)) {
while (m_atomic.load(std::memory_order_relaxed) || !m_atomic.compare_exchange_strong(exp, true)) {
exp = false;
}
}