Commit 46183b6c authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix compare_exchange_strong memory order in Core

Reviewed By: lewissbaker

Differential Revision: D15114457

fbshipit-source-id: 0f49d631bd316fda828946971b607c94ee75250b
parent d9f6a3fd
......@@ -314,7 +314,10 @@ class Core final {
if (state == State::Start) {
if (state_.compare_exchange_strong(
state, State::OnlyCallback, std::memory_order_release)) {
state,
State::OnlyCallback,
std::memory_order_release,
std::memory_order_acquire)) {
return;
}
assume(state == State::OnlyResult || state == State::Proxy);
......@@ -348,7 +351,10 @@ class Core final {
switch (state) {
case State::Start:
if (state_.compare_exchange_strong(
state, State::Proxy, std::memory_order_release)) {
state,
State::Proxy,
std::memory_order_release,
std::memory_order_acquire)) {
break;
}
assume(state == State::OnlyCallback);
......@@ -379,29 +385,27 @@ class Core final {
::new (&result_) Result(std::move(t));
auto state = state_.load(std::memory_order_acquire);
while (true) {
switch (state) {
case State::Start:
if (state_.compare_exchange_strong(
state, State::OnlyResult, std::memory_order_release)) {
state,
State::OnlyResult,
std::memory_order_release,
std::memory_order_acquire)) {
return;
}
assume(state == State::OnlyCallback);
FOLLY_FALLTHROUGH;
case State::OnlyCallback:
if (state_.compare_exchange_strong(
state, State::Done, std::memory_order_release)) {
state_.store(State::Done, std::memory_order_relaxed);
doCallback();
return;
}
FOLLY_FALLTHROUGH;
default:
terminate_with<std::logic_error>("setResult unexpected state");
}
}
}
/// Called by a destructing Future (in the consumer thread, by definition).
/// Calls `delete this` if there are no more references to `this`
......
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