Commit 9888c327 authored by fdoray's avatar fdoray Committed by Commit bot

Synchronize memory in TaskTracker::Flush().

To prevent races, make sure that code that runs after
TaskTracker::Flush() sees memory changed by all tasks it was waiting
for.

BUG=717527

Review-Url: https://codereview.chromium.org/2857613002
Cr-Commit-Position: refs/heads/master@{#469008}
parent 1d44ab0e
......@@ -215,7 +215,7 @@ void TaskTracker::Shutdown() {
void TaskTracker::Flush() {
AutoSchedulerLock auto_lock(flush_lock_);
while (subtle::NoBarrier_Load(&num_pending_undelayed_tasks_) != 0 &&
while (subtle::Acquire_Load(&num_pending_undelayed_tasks_) != 0 &&
!IsShutdownComplete()) {
flush_cv_->Wait();
}
......@@ -484,7 +484,7 @@ void TaskTracker::OnBlockingShutdownTasksComplete() {
void TaskTracker::DecrementNumPendingUndelayedTasks() {
const auto new_num_pending_undelayed_tasks =
subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
subtle::Barrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
DCHECK_GE(new_num_pending_undelayed_tasks, 0);
if (new_num_pending_undelayed_tasks == 0) {
AutoSchedulerLock auto_lock(flush_lock_);
......
......@@ -117,9 +117,9 @@ class BASE_EXPORT TaskTracker {
const std::unique_ptr<State> state_;
// Number of undelayed tasks that haven't completed their execution. Is
// incremented and decremented without a barrier. When it reaches zero,
// |flush_lock_| is acquired (forcing memory synchronization) and |flush_cv_|
// is signaled.
// decremented with a memory barrier after a task runs. Is accessed with an
// acquire memory barrier in Flush(). The memory barriers ensure that the
// memory written by flushed tasks is visible when Flush() returns.
subtle::Atomic32 num_pending_undelayed_tasks_ = 0;
// Lock associated with |flush_cv_|. Partially synchronizes access to
......
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