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

Unified Diff: device/generic_sensor/platform_sensor_linux.cc

Issue 2569763004: [sensors](Linux) Fix tsan data race in sensor reader (Closed)
Patch Set: don't use pointer for timer 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
Index: device/generic_sensor/platform_sensor_linux.cc
diff --git a/device/generic_sensor/platform_sensor_linux.cc b/device/generic_sensor/platform_sensor_linux.cc
index 55aa1398d1499c7bd61bfc4ec10b1199b5087c85..df6e22ba19377efb9f350d0fc6ac0b38c48ca244 100644
--- a/device/generic_sensor/platform_sensor_linux.cc
+++ b/device/generic_sensor/platform_sensor_linux.cc
@@ -4,6 +4,7 @@
#include "device/generic_sensor/platform_sensor_linux.h"
+#include "base/bind_to_current_loop.h"
#include "device/generic_sensor/linux/sensor_data_linux.h"
#include "device/generic_sensor/platform_sensor_reader_linux.h"
@@ -29,12 +30,25 @@ PlatformSensorLinux::PlatformSensorLinux(
default_configuration_(
PlatformSensorConfiguration(sensor_device->device_frequency)),
reporting_mode_(sensor_device->reporting_mode),
+ polling_thread_task_runner_(std::move(polling_thread_task_runner)),
weak_factory_(this) {
- sensor_reader_ =
- SensorReader::Create(sensor_device, this, polling_thread_task_runner);
+ SensorReader::UpdateSensorReadingCallback update_reading_cb =
+ base::BindToCurrentLoop(
+ base::Bind(&PlatformSensorLinux::UpdatePlatformSensorReading,
+ weak_factory_.GetWeakPtr()));
+ SensorReader::NotifyReadErrorCallback notify_read_error_cb =
+ base::BindToCurrentLoop(
+ base::Bind(&PlatformSensorLinux::NotifyPlatformSensorError,
+ weak_factory_.GetWeakPtr()));
+
+ sensor_reader_ = SensorReader::Create(
+ sensor_device, task_runner_, update_reading_cb, notify_read_error_cb);
Reilly Grant (use Gerrit) 2016/12/15 18:51:31 Since these callbacks are bound to the current mes
maksims (do not use this acc) 2016/12/16 08:39:22 I think passing a callback with binded weakPtr to
}
-PlatformSensorLinux::~PlatformSensorLinux() = default;
+PlatformSensorLinux::~PlatformSensorLinux() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ polling_thread_task_runner_->DeleteSoon(FROM_HERE, sensor_reader_.release());
+}
mojom::ReportingMode PlatformSensorLinux::GetReportingMode() {
DCHECK(task_runner_->BelongsToCurrentThread());
@@ -62,15 +76,18 @@ void PlatformSensorLinux::NotifyPlatformSensorError() {
bool PlatformSensorLinux::StartSensor(
const PlatformSensorConfiguration& configuration) {
DCHECK(task_runner_->BelongsToCurrentThread());
- if (!sensor_reader_)
- return false;
- return sensor_reader_->StartFetchingData(configuration);
+ polling_thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&SensorReader::StartFetchingData,
+ base::Unretained(sensor_reader_.get()), configuration));
+ return true;
}
void PlatformSensorLinux::StopSensor() {
DCHECK(task_runner_->BelongsToCurrentThread());
- DCHECK(sensor_reader_);
- sensor_reader_->StopFetchingData();
+ polling_thread_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&SensorReader::StopFetchingData,
+ base::Unretained(sensor_reader_.get())));
}
bool PlatformSensorLinux::CheckSensorConfiguration(
« no previous file with comments | « device/generic_sensor/platform_sensor_linux.h ('k') | device/generic_sensor/platform_sensor_provider_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698