Commit 943b1bce authored by erikchen's avatar erikchen Committed by Commit Bot

Fix data race for SetAddQueueTimeToTasks().

Switch to an atomic variable to ensure that getter and setter do not have a data
race.

Bug: 859155
Change-Id: Ib5ab1968cc8e25ab363fb4ed0b3f2e756d9cc984
Reviewed-on: https://chromium-review.googlesource.com/1240634
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594079}
parent 991fa1ab
......@@ -108,8 +108,7 @@ void MessageLoopTaskRunner::InjectTask(OnceClosure task) {
}
void MessageLoopTaskRunner::SetAddQueueTimeToTasks(bool enable) {
DCHECK_NE(add_queue_time_to_tasks_, enable);
add_queue_time_to_tasks_ = enable;
base::subtle::NoBarrier_Store(&add_queue_time_to_tasks_, enable ? 1 : 0);
}
MessageLoopTaskRunner::~MessageLoopTaskRunner() = default;
......@@ -127,7 +126,8 @@ bool MessageLoopTaskRunner::AddToIncomingQueue(const Location& from_here,
PendingTask pending_task(from_here, std::move(task),
CalculateDelayedRuntime(from_here, delay), nestable);
if (add_queue_time_to_tasks_) {
if (base::subtle::NoBarrier_Load(&add_queue_time_to_tasks_)) {
if (pending_task.delayed_run_time.is_null()) {
pending_task.queue_time = base::TimeTicks::Now();
} else {
......
......@@ -5,6 +5,7 @@
#ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_
#define BASE_MESSAGE_LOOP_MESSAGE_LOOP_TASK_RUNNER_H_
#include "base/atomicops.h"
#include "base/base_export.h"
#include "base/callback.h"
#include "base/macros.h"
......@@ -105,7 +106,7 @@ class BASE_EXPORT MessageLoopTaskRunner : public SingleThreadTaskRunner,
int next_sequence_num_ = 0;
// Whether to add the queue time to tasks.
bool add_queue_time_to_tasks_ = false;
base::subtle::Atomic32 add_queue_time_to_tasks_ = 0;
DISALLOW_COPY_AND_ASSIGN(MessageLoopTaskRunner);
};
......
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