Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Unified Diff: device/generic_sensor/platform_sensor_reader_linux.cc

Issue 2569763004: [sensors](Linux) Fix tsan data race in sensor reader (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/generic_sensor/platform_sensor_reader_linux.cc
diff --git a/device/generic_sensor/platform_sensor_reader_linux.cc b/device/generic_sensor/platform_sensor_reader_linux.cc
index 5c014a4b200b43b9f8697bcfa8c5ee1cfc457fb9..143b1987a455374e925c9ef8e8eef4f74b1d5373 100644
--- a/device/generic_sensor/platform_sensor_reader_linux.cc
+++ b/device/generic_sensor/platform_sensor_reader_linux.cc
@@ -74,6 +74,7 @@ PollingSensorReader::~PollingSensorReader() {
bool PollingSensorReader::StartFetchingData(
const PlatformSensorConfiguration& configuration) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
if (is_reading_active_)
StopFetchingData();
@@ -83,6 +84,7 @@ bool PollingSensorReader::StartFetchingData(
}
void PollingSensorReader::StopFetchingData() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
is_reading_active_ = false;
timer_->Stop();
}
@@ -108,7 +110,9 @@ void PollingSensorReader::PollForData() {
std::string new_read_value;
if (!base::ReadFileToString(path, &new_read_value)) {
NotifyReadError();
- StopFetchingData();
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&PollingSensorReader::StopFetchingData,
+ weak_factory_.GetWeakPtr()));
return;
}
@@ -116,7 +120,9 @@ void PollingSensorReader::PollForData() {
base::TrimWhitespaceASCII(new_read_value, base::TRIM_ALL, &new_read_value);
if (!base::StringToDouble(new_read_value, &new_value)) {
NotifyReadError();
- StopFetchingData();
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&PollingSensorReader::StopFetchingData,
+ weak_factory_.GetWeakPtr()));
gab 2016/12/13 18:12:45 WeakPtr is also not thread-safe (can't obtain it o
maksims (do not use this acc) 2016/12/13 18:18:19 Do you mean I need 2 to create two different weak
gab 2016/12/13 18:23:02 classes in Chromium are typically bound to a singl
return;
}
readings.values[i++] = new_value;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698