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

Fix memory order usage in SerialExecutor::run

Summary: We want to have a guarantee that if f1() was run before f2(), then all writes done by f1() are also observable by f2().

Reviewed By: yfeldblum, davidtgoldblatt

Differential Revision: D12982731

fbshipit-source-id: 2170e977a879d27d2daf1b5307441594e6aae00b
parent 7919e65c
...@@ -68,7 +68,9 @@ void SerialExecutor::addWithPriority(Func func, int8_t priority) { ...@@ -68,7 +68,9 @@ void SerialExecutor::addWithPriority(Func func, int8_t priority) {
} }
void SerialExecutor::run() { void SerialExecutor::run() {
if (scheduled_.fetch_add(1, std::memory_order_relaxed) > 0) { // We want scheduled_ to guard side-effects of completed tasks, so we can't
// use std::memory_order_relaxed here.
if (scheduled_.fetch_add(1, std::memory_order_acquire) > 0) {
return; return;
} }
...@@ -86,7 +88,9 @@ void SerialExecutor::run() { ...@@ -86,7 +88,9 @@ void SerialExecutor::run() {
"object"; "object";
} }
} while (scheduled_.fetch_sub(1, std::memory_order_relaxed) > 1); // We want scheduled_ to guard side-effects of completed tasks, so we can't
// use std::memory_order_relaxed here.
} while (scheduled_.fetch_sub(1, std::memory_order_release) > 1);
} }
} // namespace folly } // namespace folly
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