Commit db8ef89b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

let c/x expected and value params be dependent

Summary: Let their types be determined by the atomic parameter only so that conversions may happen at the call-site. This is what the `std::atomic_compare_exchange` functions do. Those functions are specified to use `typename std::atomic<T>::value_type` rather than `T` but, curiously, not all implementations of `std::atomic` have member type alias `value_type`. So instead of using member type alias `value_type` to get dependency, we use `type_t`.

Reviewed By: ot

Differential Revision: D32259208

fbshipit-source-id: 413e3580aff3dd0ece5051b7a62dfd16f49eb5a8
parent fb8d10f5
......@@ -60,7 +60,7 @@ bool Baton::waitImpl(WaitOperation* awaiter) const noexcept {
} while (!folly::atomic_compare_exchange_weak_explicit(
&state_,
&oldValue,
static_cast<void*>(awaiter),
awaiter,
std::memory_order_release,
std::memory_order_acquire));
return true;
......
......@@ -23,7 +23,6 @@
#include <type_traits>
#include <folly/Portability.h>
#include <folly/Traits.h>
#ifdef _WIN32
#include <intrin.h>
......@@ -84,8 +83,8 @@ constexpr std::memory_order atomic_compare_exchange_succ(
template <template <typename> class Atom, typename T>
bool atomic_compare_exchange_weak_explicit(
Atom<T>* obj,
T* expected,
T desired,
type_t<T>* expected,
type_t<T> desired,
std::memory_order succ,
std::memory_order fail) {
succ = detail::atomic_compare_exchange_succ(succ, fail);
......@@ -95,8 +94,8 @@ bool atomic_compare_exchange_weak_explicit(
template <template <typename> class Atom, typename T>
bool atomic_compare_exchange_strong_explicit(
Atom<T>* obj,
T* expected,
T desired,
type_t<T>* expected,
type_t<T> desired,
std::memory_order succ,
std::memory_order fail) {
succ = detail::atomic_compare_exchange_succ(succ, fail);
......
......@@ -19,6 +19,8 @@
#include <atomic>
#include <cstdint>
#include <folly/Traits.h>
namespace folly {
// atomic_compare_exchange_weak_explicit
......@@ -30,8 +32,8 @@ namespace folly {
template <template <typename> class Atom = std::atomic, typename T>
bool atomic_compare_exchange_weak_explicit(
Atom<T>* obj,
T* expected,
T desired,
type_t<T>* expected,
type_t<T> desired,
std::memory_order succ,
std::memory_order fail);
......@@ -44,8 +46,8 @@ bool atomic_compare_exchange_weak_explicit(
template <template <typename> class Atom = std::atomic, typename T>
bool atomic_compare_exchange_strong_explicit(
Atom<T>* obj,
T* expected,
T desired,
type_t<T>* expected,
type_t<T> desired,
std::memory_order succ,
std::memory_order fail);
......
......@@ -312,7 +312,7 @@ class Baton {
if (!folly::atomic_compare_exchange_strong_explicit<Atom>(
&state_,
&expected,
static_cast<uint32_t>(WAITING),
WAITING,
std::memory_order_relaxed,
std::memory_order_acquire)) {
// CAS failed. The baton must have been posted between the last spin and
......
......@@ -300,7 +300,7 @@ FOLLY_NOINLINE bool SaturatingSemaphore<MayBlock, Atom>::tryWaitSlow(
!folly::atomic_compare_exchange_weak_explicit<Atom>(
&state_,
&before,
static_cast<std::uint32_t>(BLOCKED),
BLOCKED,
std::memory_order_relaxed,
std::memory_order_acquire)) {
if (before == READY) {
......
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