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 { ...@@ -314,7 +314,10 @@ class Core final {
if (state == State::Start) { if (state == State::Start) {
if (state_.compare_exchange_strong( if (state_.compare_exchange_strong(
state, State::OnlyCallback, std::memory_order_release)) { state,
State::OnlyCallback,
std::memory_order_release,
std::memory_order_acquire)) {
return; return;
} }
assume(state == State::OnlyResult || state == State::Proxy); assume(state == State::OnlyResult || state == State::Proxy);
...@@ -348,7 +351,10 @@ class Core final { ...@@ -348,7 +351,10 @@ class Core final {
switch (state) { switch (state) {
case State::Start: case State::Start:
if (state_.compare_exchange_strong( if (state_.compare_exchange_strong(
state, State::Proxy, std::memory_order_release)) { state,
State::Proxy,
std::memory_order_release,
std::memory_order_acquire)) {
break; break;
} }
assume(state == State::OnlyCallback); assume(state == State::OnlyCallback);
...@@ -379,27 +385,25 @@ class Core final { ...@@ -379,27 +385,25 @@ class Core final {
::new (&result_) Result(std::move(t)); ::new (&result_) Result(std::move(t));
auto state = state_.load(std::memory_order_acquire); auto state = state_.load(std::memory_order_acquire);
while (true) { switch (state) {
switch (state) { case State::Start:
case State::Start: if (state_.compare_exchange_strong(
if (state_.compare_exchange_strong( state,
state, State::OnlyResult, std::memory_order_release)) { State::OnlyResult,
return; std::memory_order_release,
} std::memory_order_acquire)) {
assume(state == State::OnlyCallback); return;
FOLLY_FALLTHROUGH; }
assume(state == State::OnlyCallback);
case State::OnlyCallback: FOLLY_FALLTHROUGH;
if (state_.compare_exchange_strong(
state, State::Done, std::memory_order_release)) { case State::OnlyCallback:
doCallback(); state_.store(State::Done, std::memory_order_relaxed);
return; doCallback();
} return;
FOLLY_FALLTHROUGH;
default:
default: terminate_with<std::logic_error>("setResult unexpected state");
terminate_with<std::logic_error>("setResult unexpected state");
}
} }
} }
......
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