Commit f75211c0 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Stop using atomic_thread_fence in folly::Baton

Summary: Thread fences are not supported by TSAN

Reviewed By: yfeldblum

Differential Revision: D21989519

fbshipit-source-id: bb657c82a64abe025e8f4c030916c0cacc3c0b81
parent 2c9b2aad
...@@ -62,28 +62,26 @@ constexpr std::memory_order atomic_compare_exchange_succ( ...@@ -62,28 +62,26 @@ constexpr std::memory_order atomic_compare_exchange_succ(
} // namespace detail } // namespace detail
template <typename T> template <template <typename> class Atom, typename T>
bool atomic_compare_exchange_weak_explicit( bool atomic_compare_exchange_weak_explicit(
std::atomic<T>* obj, Atom<T>* obj,
T* expected, T* expected,
T desired, T desired,
std::memory_order succ, std::memory_order succ,
std::memory_order fail) { std::memory_order fail) {
succ = detail::atomic_compare_exchange_succ(succ, fail); succ = detail::atomic_compare_exchange_succ(succ, fail);
return std::atomic_compare_exchange_weak_explicit( return obj->compare_exchange_weak(*expected, desired, succ, fail);
obj, expected, desired, succ, fail);
} }
template <typename T> template <template <typename> class Atom, typename T>
bool atomic_compare_exchange_strong_explicit( bool atomic_compare_exchange_strong_explicit(
std::atomic<T>* obj, Atom<T>* obj,
T* expected, T* expected,
T desired, T desired,
std::memory_order succ, std::memory_order succ,
std::memory_order fail) { std::memory_order fail) {
succ = detail::atomic_compare_exchange_succ(succ, fail); succ = detail::atomic_compare_exchange_succ(succ, fail);
return std::atomic_compare_exchange_strong_explicit( return obj->compare_exchange_strong(*expected, desired, succ, fail);
obj, expected, desired, succ, fail);
} }
namespace detail { namespace detail {
......
...@@ -27,9 +27,9 @@ namespace folly { ...@@ -27,9 +27,9 @@ namespace folly {
// Workaround for https://github.com/google/sanitizers/issues/970. // Workaround for https://github.com/google/sanitizers/issues/970.
// //
// mimic: std::atomic_compare_exchange_weak // mimic: std::atomic_compare_exchange_weak
template <typename T> template <template <typename> class Atom = std::atomic, typename T>
bool atomic_compare_exchange_weak_explicit( bool atomic_compare_exchange_weak_explicit(
std::atomic<T>* obj, Atom<T>* obj,
T* expected, T* expected,
T desired, T desired,
std::memory_order succ, std::memory_order succ,
...@@ -41,9 +41,9 @@ bool atomic_compare_exchange_weak_explicit( ...@@ -41,9 +41,9 @@ bool atomic_compare_exchange_weak_explicit(
// Workaround for https://github.com/google/sanitizers/issues/970. // Workaround for https://github.com/google/sanitizers/issues/970.
// //
// mimic: std::atomic_compare_exchange_strong // mimic: std::atomic_compare_exchange_strong
template <typename T> template <template <typename> class Atom = std::atomic, typename T>
bool atomic_compare_exchange_strong_explicit( bool atomic_compare_exchange_strong_explicit(
std::atomic<T>* obj, Atom<T>* obj,
T* expected, T* expected,
T desired, T desired,
std::memory_order succ, std::memory_order succ,
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <folly/detail/Futex.h> #include <folly/detail/Futex.h>
#include <folly/detail/MemoryIdler.h> #include <folly/detail/MemoryIdler.h>
#include <folly/portability/Asm.h> #include <folly/portability/Asm.h>
#include <folly/synchronization/AtomicUtil.h>
#include <folly/synchronization/WaitOptions.h> #include <folly/synchronization/WaitOptions.h>
#include <folly/synchronization/detail/Spin.h> #include <folly/synchronization/detail/Spin.h>
...@@ -292,15 +293,14 @@ class Baton { ...@@ -292,15 +293,14 @@ class Baton {
// guess we have to block :( // guess we have to block :(
uint32_t expected = INIT; uint32_t expected = INIT;
if (!state_.compare_exchange_strong( if (!folly::atomic_compare_exchange_strong_explicit<Atom>(
expected, &state_,
WAITING, &expected,
static_cast<uint32_t>(WAITING),
std::memory_order_relaxed, std::memory_order_relaxed,
std::memory_order_relaxed)) { std::memory_order_acquire)) {
// CAS failed, last minute reprieve // CAS failed, last minute reprieve
assert(expected == EARLY_DELIVERY); assert(expected == EARLY_DELIVERY);
// TODO: move the acquire to the compare_exchange failure load after C++17
std::atomic_thread_fence(std::memory_order_acquire);
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment